mdeguzis / SteamOS-Tools

Tools, scripts, and hosted packages for SteamOS.
http://www.libregeek.org
GNU General Public License v3.0
191 stars 24 forks source link

Wine Steam Application Launching Script #109

Closed Ryochan7 closed 8 years ago

Ryochan7 commented 8 years ago

I figured that there were probably decisions to be made about the script's placement in this repository and how to better customize it so I figure that filing this as an issue would be better than a pull request. Here is the current version. It has been commented and cleaned up a little bit. This version is used to launch Serious Sam 2 on my system.

<! code edited out by PK, see latest in cfgs/wine/pol-game-launcher.skel !>

Progress Tracker (Please do not remove)

mdeguzis commented 8 years ago

Fantastic work Ryochan. In about off to bed, catching up on sleep. I will be without internet (cabin trip) until Friday. I may get a chance at lunch to look it over. I appreciate the contribution very much. We can discuss this then. Maybe a small loader script that applies values to the variables is fine.

In-script, it could list the virtual drives/bottles and source the information then. Should be fun! And of course, I recognize Ivan's and others work. When this is finalized, all of you involved wipp go in the authors file.

mdeguzis commented 8 years ago

Work will commence under here for now (until finalized):

mdeguzis commented 8 years ago

I started a bit of script code in wine-utils.shinc and in configs directory. Rough draft items. I tried testing Serious Sam HD: The Second Encounter but received a lot of errors on XAudio2 and DirectX. Possibly since I used "1.7.53-steam_crossoverhack" instead of 1.8. 1.8 seemed to work just fine to launch, but it was very slow on my Intel core 2 quad @ 3 GHz, Nvidia GT 640. Maybe for what I am running, that is a bad combo :) i'll have to test a game I know will run fine. Going to install Super Indie Karts, since I would like to have that running.

Got a lot of testing to do this weekend. I'll need some help getting things as "easy" as can be from a user perspective.

I am really considering just putting up a wiki page, since automating this will be probably too much. There too many "what ifs" to consider.

mdeguzis commented 8 years ago

Page is up: https://github.com/ProfessorKaos64/SteamOS-Tools/wiki/Playing-Steam-for-Windows-Games-On-SteamOS

RobLoach commented 8 years ago

If you're using PlayOnLinux, you can launch games directly through it by appending --run "GameName" to the end of the launch options too.

Lutris facilitates Steam Wine game launching quite well as well, if you're looking for alternatives.

mdeguzis commented 8 years ago

I am going to test the Kodi addon soon. For Lutris game launching, have you done this under SteamOS BPM? If so, do you mind sharing some files for testing? The POL option would be nice if users were installing games other than the Steam "game" in the guide. I'll have to add that note in the wiki though for other games outside of Steam.

Ryochan7 commented 8 years ago

Using --run "GameName" does not work properly in the SteamOS session; just to note, I am using POL version 4.2.8. That method works better now than it had in the past since steamcompmgr is now able to grab the proper game window. However, on my system, launching games that way causes the BPM overlay to not work and it causes Steam to crash after quitting a game. Previously, I used to use playonlinux-bash for launching the shortcuts created by POL but that works just like --run "GameName" does now. Copying over the main code (before the POL_Wine line) from a POL shortcut in ~/.PlayOnLinux/shortcuts/ works fine. I am testing using System Shock 2 from GOG.

I haven't used Lutris in a long time but using Lutris did make launching Wine games in SteamOS BPM much simpler. lutris lutris:system-shock-2 is all that was needed in a script to make things work. I don't know if Lutris would make launching games from the Windows Steam client that much easier though.

dubigrasu commented 8 years ago

"# NOTE: GAME_DIR is not used with current method. Possibly remove?"

I use "GAME_DIR" in my scripts because the "applaunch" command is insufficient to properly launch the game in some cases. If you use the "applaunch" command Steam will only launch the default exec, for example a launcher (Awesome_Game_launcher) which may be in conflict with Wine (and especially steamcompmgr) for various reasons and preventing the game from starting. In cases like this the game may still be started from the actual game exec (Awesome_Game) with:

$WINEVERSION/bin/wine $VIRT_DESK "$STEAM_DIR"/"$GAME_DIR"/"$GAME_EXEC"

For example, occasionally the "applaunch" may trigger an options selector window (safe mode/windowed/fullscreen/Directx9/DirectX11/config etc) which could be cumbersome to use (or even impossible) if you only have a controller attached. In some other cases the launcher may try (and worse, fail) to do some silly things in the background like trying to connect to some site or display some window before starting the game making the launching process to hang (and in turn Steam client to shutdown).

At the same time the "applaunch" is a Steam-only command not usable for Uplay or Origin games scripts for example:

#!/bin/bash

export WINEPREFIX="$HOME/.PlayOnLinux/wineprefix/Origin"
export WINEDEBUG="-all"

xset -dpms
xset s off

MY_RES=`xrandr -q | awk -F'current' -F',' 'NR==1 {gsub("( |current)","");print $2}'`
VIRT_DESK="explorer /desktop=Origin,$MY_RES"
WINEVERSION="$HOME/.PlayOnLinux/wine/linux-x86/1.7.47-staging"
WARP_ON="$WINEVERSION/bin/wine REG ADD HKEY_CURRENT_USER\\Software\\Wine\\DirectInput /v MouseWarpOverride /t Reg_Sz /d force"
WARP_OFF="$WINEVERSION/bin/wine REG DELETE HKEY_CURRENT_USER\\Software\\Wine\\DirectInput /v MouseWarpOverride /t Reg_Sz /d force" 
GAME_DIR="$WINEPREFIX/drive_c/Program Files/Origin Games/Medal of Honor/Binaries"
GAME_EXEC="moh.exe"

# fix the limited range mouse issue
$WARP_ON
# start the xboxdrv profile
$HOME/profiles/moh &

# make steamcompmgr happy
if [ "${SteamTenfoot}" -eq "1" ]; then
$WINEVERSION/bin/wine "$GAME_DIR"/"$GAME_EXEC"
else
$WINEVERSION/bin/wine $VIRT_DESK "$GAME_DIR"/"$GAME_EXEC"
fi

sleep 10
# set the mouse warp as it was before
while ps -C "$GAME_EXEC" > /dev/null; do sleep 5; done; $WARP_OFF &&
# kill everything
$WINEVERSION/bin/wineserver -k & killall xboxdrv
# just to be sure
xrandr -s $MY_RES

Uplay and Origin may have their own arguments similar with "applaunch", but in the end having too many different methods to do the same thing is a bit redundant so I don't use applaunch & GAME_APPID at all.

mdeguzis commented 8 years ago

@dubigrasu @Ryochan7 , think it would then be good to have a template for such games or just create if/fi logic in the header. We can create a "game_type=" and note to set that to steam,uplay, origin etc. ?

Ryochan7 commented 8 years ago

One problem that I have is that some games in my library seem to require Steam to launch the game in order for the game to load properly. Attempting to directly launch some games causes various problems when done in Windows 8.1 as well as Wine. Skyrim will proceed to launch Steam and have the client launch the game; that causes the Skyrim launcher window to appear anyway. Serious Sam 2 just crashes if not launched from Steam. Ultra Street Fighter 4 just brings up a window saying that SteamAPI_Init has failed or something to that effect. For the current script, launching the virtual desktop on its own and then blanking LD_PRELOAD is what is being used to make steamcompmgr play nice.

I have thought about changing the working directory to GAME_DIR but I haven't found a case where it was needed when launching Windows games from the Windows Steam client; launching System Shock 2 (GOG) directly is one case where the game will fail to launch if the working directory is not the game directory so there is a reason to use it for games launched directly.

As for updates, I have found a minor change that will actually allow games to be launched from the Windows Steam client in one call. When using env to start a clean environment, there is no need to launch the Windows Steam client and then wait for the main window to fully load before attempting to launch the game. This has worked for me during testing but there should be a shorter way to specify environmental variables to carry over. There are probably other variables that should be carried over as well.

env -i DISPLAY=$DISPLAY WINEPREFIX=$WINEPREFIX WINEDEBUG=$WINEDEBUG LD_LIBRARY_PATH=$LD_LIBRARY_PATH PATH=$PATH "$WINEVERSION/bin/wine" "$STEAM_DIR/Steam.exe" -applaunch "$GAME_APPID" &

Updated template script: https://gist.github.com/Ryochan7/d5cd8256964237063e00

It would be nice to find ways to reduce the need for special scripts for services being utilized. Directly launching an application is the best method when it is an option but work does need to be done for some games that require the use of services like Steam and Origin.

mdeguzis commented 8 years ago

that env update seemed to work for me too @Ryochan7 , added, thank you very much. commit 38f2df9a

dubigrasu commented 8 years ago

Attempting to directly launch some games causes various problems when done in Windows 8.1 as well as Wine. Skyrim will proceed to launch Steam and have the client launch the game; that causes the Skyrim launcher window to appear anyway. Serious Sam 2 just crashes if not launched from Steam. Ultra Street Fighter 4 just brings up a window saying that SteamAPI_Init has failed or something to that effect.

What you're are describing is what happens when you try to start the game directly without having the Steam client loaded already (SteamAPI_Init has failed). So to be exact, I'm not talking about starting the games directly before starting the Steam client, but having the Steam client started and then start the game directly, as in:

$WINEVERSION/bin/wine "$STEAM_DIR"/Steam.exe -silent & sleep 8 $WINEVERSION/bin/wine "$STEAM_DIR"/"$GAME_DIR"/"$GAME_EXEC"

You won't have any problems this way (or to be correct, I didn't had any problems with the gazzilions of games I tried).

I have thought about changing the working directory to GAME_DIR but I haven't found a case where it was needed when launching Windows games from the Windows Steam client

Give it enough time and games and you'll bump into those as well :) Initially I used applaunch as well (because it seemed the right/elegant way to do it), but eventually it made more sense to have a simplified/unified script template that works for every game outhere regardless if it uses Steam/Origin/Uplay or is a standalone game.

mdeguzis commented 8 years ago

@dubigrasu , If you don't mind, could you submit a PR against the current template? If you've tested it enough, I trust your judgement as well as Ryochan. Both smart people :) I appreciate both of you looking at this. I'm glad just to offer it from a central place.

dubigrasu commented 8 years ago

Well, there's one more thing I need to test though, I'm having some issues with the SteamOS BPM overlay if I load only the desktop first (as described above):

# Change to Steam directory and launch Wine virtual desktop.
cd "$STEAM_DIR"
$WINEVERSION/bin/wine $VIRT_DESK &

# Allow a little sleep time so steamcompmgr uses the virtual desktop
# window.
sleep 3

# Don't use extra libraries for other applications running in Wine.
# The virtual desktop will be used by steamcompmgr.
export LD_PRELOAD=

# Launch Steam client.
"$WINEVERSION/bin/wine" $VIRT_DESK "$STEAM_DIR/Steam.exe" -silent &

More exactly I'm having problems trying to bring up the overlay (to adjust the controller). The overlay seem to be very sluggish this way. I need to test this more.

Ryochan7 commented 8 years ago

I have tried it again and Serious Sam 2 launches fine most of the time; in some situations, the game window appears minimized and it can be a bit of a struggle to get the window full screen. Street Fighter 4 has the same problem as before even when the Steam client is already loaded even on Windows. Skyrim still behaves the same with the executable deferring to Steam and loading the launcher window.

I don't have a problem with the Steam overlay being sluggish when Windows games are launched with the current script. When I was not using a virtual desktop method, it could take many Guide button presses in order for the overlay to appear due to multiple windows being loaded with the overlay library. Also, Skyrim would constantly experience mouse pointer issues and flicker due to multiple windows trying to grab focus. The virtual desktop method has been more reliable for me so far.

Although, if it would be possible without major compromises, I would prefer to use a method that didn't rely on the Wine virtual desktop. The major compromise with just having LD_PRELOAD used for the game executable is if something would go wrong with Steam (login credentials needed) and the window would not be visible.

dubigrasu commented 8 years ago

I have tried it again and Serious Sam 2 launches fine most of the time; in some situations, the game window appears minimized and it can be a bit of a struggle to get the window full screen.

But that's in desktop mode right?

it could take many Guide button presses in order for the overlay to appear due to multiple windows being loaded with the overlay library.

Yes, that's exactly what happens to me if I load only the desktop first. Apart from that, I can't load any new config for the Steam Controller (except for the one I had when the virtual desktop started).

dubigrasu commented 8 years ago

OK, I bought Skyrim to see if I can reproduce the issue you're having. Serious Sam 2 works without issues but I don't have USF4 to test it (and is too expensive).

dubigrasu commented 8 years ago

I tested Skyrim and I see what you're saying about the game launcher being triggered anyway in this case. Regardless of the method used (applaunch or directly executing SkyrimLauncher.exe or TESV.exe) the launcher window still gets triggered. But at the same time the behavior is identical with all three methods, so even here the applaunch command is still not mandatory.

Don't know what to say about USF4 since I don't have the game.

Ryochan7 commented 8 years ago

The Serious Sam 2 issue mainly happens when testing the script in the Gnome session. Although, I have run into problems when launching it from within the SteamOS session on occasion when directly launching the game exe after the Windows Steam client launches. During those cases, the window will be full screen but the game will just not load with no error window appearing. It could be an odd issue on my end from testing.

Yes, that's exactly what happens to me if I load only the desktop first. Apart from that, I can't load any new config for the Steam Controller (except for the one I had when the virtual desktop started).

It seems like the Windows Steam client has to be in Offline Mode in order to use and customize the Steam Controller bindings for Windows games. If the Windows Steam client is run normally, it causes some weird problems with controller bindings and it causes problems with the binding UI portion of Steam that will require Steam to be restarted in order to fix.

As for the Skyrim launcher quirk, that quirk could be worked around easily enough with an extra sleep time set so that the script doesn't see the executable before it calls Steam and exits.

dubigrasu commented 8 years ago

The Serious Sam 2 issue mainly happens when testing the script in the Gnome session.

This is something I see frequently (in desktop mode) when using virtual desktop, it happens with or without a script unfortunately.

It seems like the Windows Steam client has to be in Offline Mode in order to use and customize the Steam Controller bindings for Windows games. If the Windows Steam client is run normally, it causes some weird problems with controller bindings and it causes problems with the binding UI portion of Steam that will require Steam to be restarted in order to fix.

Could be (haven't tried have it offline) but a sure way that solves the issue for me is to run everything in full screen (no VIRT_DESK). What I do with with Windows Steam client is disable everything that might create issues, just in case, like disable friends/overlay and such, but still keep it online.

One thing I want to say about VIRT_DESK. Initially when I started the scrip the only reason I added RES+VIRT_DESK for was aesthetics and nothing else. I hated how the game startup sequence looked like, how every small icon/taskbar and desktop element were stretched full-screen. With a virtual desktop you can create a customized (add a SteamOS themed wallpaper for Wine) and clean startup for games: https://www.youtube.com/watch?v=aRk12DtBS78 but it also allows you to run other apps (like the Uplay/Steam/Origin clients) without being affected by steamcompmgr: https://www.youtube.com/watch?v=yxlZB3Ph4wM

But now when it comes to gaming with the Steam Controller+Overlay it is a pain in the back to have running in the background. Sometimes it works, sometimes it doesn't and at least for now I have it disabled when I start a game. I still use it for apps but that's it.

Ryochan7 commented 8 years ago

I tried with and without using the virtual desktop and that didn't seem to affect changing the bindings of the Steam Controller. Either way, you get one shot and then the interface bugs out and changes don't stick; restarting the Linux Steam client is then required. It really seems more like a issue caused by having both instances of Steam running. Based on my testing, other games that don't need Steam running don't have this problem when using the virtual desktop.

One piece of functionality that definitely has no way of working with the current VIRT_DESK method is the virtual keyboard. The actual game needs to have the overlay library loaded in order for the virtual keyboard to work properly.

One other piece of information that might be useful either way is a way to automate activating Offline Mode for the Windows Steam client. The change that needs to be made to loginusers.vdf is documented in the following link: http://gaming.stackexchange.com/a/184717. Here is something that I hacked together to change the loginusers.vdf file.

if [ -e "$STEAM_DIR/config/loginusers.vdf" ]; then
  echo "CHANGE loginusers.vdf to use Offline Mode"
  TMP_OUTPUT=$(sed -r "s/WantsOfflineMode\"\t{1,}\"[0-1]\"/WantsOfflineMode\"\t\t\"1\"/g" "$STEAM_DIR/config/loginusers.vdf")
  echo -n "$TMP_OUTPUT" | $(sed -r "s/SkipOfflineModeWarning\"\t{1,}\"[0-1]\"/SkipOfflineModeWarning\"\t\t\"1\"/g" > "$STEAM_DIR/config/loginusers.vdf")
fi;

It should be noted that Steam will set SkipOfflineModeWarning to 0 after the Windows Steam client is loaded so that change needs to be done every time. Without that setting, the Windows Steam client would bring up an initial pop-up window confirming that you want to start Steam in Offline Mode.

dubigrasu commented 8 years ago

I tried with and without using the virtual desktop and that didn't seem to affect changing the bindings of the Steam Controller.

Curious, I have zero issues with SC without virtual screen, do you remember what games have this problem ? Indeed, standalone games are more easy to handle.

I don't know about putting the Windows client in offline mode...I mean, it does work ( I didn't test it but so told me this guy a while back: http://steamcommunity.com/groups/steamuniverse/discussions/1/537402115081717572/#c492378806379120101 ) but it feels a bit overkill.

mdeguzis commented 8 years ago

I do agree that virt desk is probably the most efficient approach right now if it also gives a more aesthetic appeal with scaling startups screens and launcher. I haven't tested Uplay or Origin yet with a virt desk, but if that does work, it's likely the choice to have. The games I have tried work well with it. The offline mode approach is a weird one. Some more tests are need to gauge how effective it is with SC bindings. I haven't tried yet to use the virtual keyboard. Is that something that LD_PRELOAD handles, or can?

dubigrasu commented 8 years ago

One question, do you guys use the same user for both Linux and Windows client?

mdeguzis commented 8 years ago

For me, yes.

Ryochan7 commented 8 years ago

Yes. I do have an alt account but I haven't done any testing with that account in a while. On Jan 20, 2016 11:30 AM, "mikeyd" notifications@github.com wrote:

For me, yes.

— Reply to this email directly or view it on GitHub https://github.com/ProfessorKaos64/SteamOS-Tools/issues/109#issuecomment-173293449 .

dubigrasu commented 8 years ago

Well, one thing that happens when I use the same account is that the Linux/SteamOS client gets put automatically in offline mode ( and the other way around). So after playing a Wine game I'm suddenly offline and can't access the store.

Ex: In desktop mode if I start the Linux client and then the Windows client (just the client) I get the "No Connection" message in Linux client. The way I have it here you can't have the same user on two separate Steam instances on the same PC. Is this working for you?

Ryochan7 commented 8 years ago

The same thing happens on my system. On my config, if the Windows Steam client is not shut down properly then many services still work in the Linux Steam BPM client temporarily; changing controller bindings stops working immediately. Services eventually stop working. Running the shutdown routine for the Windows Steam client makes many services in the Linux Steam BPM client stop working immediately. I will have to test sharing my library with an alt account and see how that works out.

dubigrasu commented 8 years ago

OK, thanks. For my setup I just use another Steam user for the Windows client, but others might not like this way. One other method is to run the Windows client offline, so here is where the script to put Windows client offline might get in handy.

In the link I mentioned earlier: http://steamcommunity.com/groups/steamuniverse/discussions/1/537402115081717572/#c492378806379120101 the guy reported the offline method as working.

I suppose you simply can't login from the same IP with two clients as the same user. Maybe using a different IP for the Windows client?

mdeguzis commented 8 years ago

I suppose you simply can't login from the same IP with two clients as the same user. Maybe using a different IP for the Windows client?

I don't know how you would even arrange that, apart from possible settings in PlayOnLinux's configuration.

Ryochan7 commented 8 years ago

I have the Windows Steam client set to my alt account for now with Family Library Sharing enabled. It is a working solution and allows Steam Controller bindings to be edited without any problems. Trying to tunnel a connection in order to keep using the same Steam account logged in on both clients would be an interesting experiment. I don't have the slightest clue how to get started though.

I have tried getting the virtual keyboard working in a virtual desktop environment. Even though it is technically possible by manipulating the SteamGameId environmental variable, the Linux Steam client does not like to play nice once the Windows Steam client is being used. Not rendering the Windows Steam client is the only way that I have gotten it to work fairly consistently.

dubigrasu commented 8 years ago

I have the Windows Steam client set to my alt account for now with Family Library Sharing enabled. It is a working solution and allows Steam Controller bindings to be edited without any problems. Trying to tunnel a connection in order to keep using the same Steam account logged in on both clients would be an interesting experiment. I don't have the slightest clue how to get started though.

Worth mentioning though a small drawback; some games are not available for Family Library Sharing.

silelmot commented 8 years ago

Hey there. I had problems with the game "Valiant Hearts". The game-exe wasnt recognized. I think it is because of the soace in "Valiant Hearts.exe".

Just for future problems like this i wanted to know tell u the problem. I solved it by changing the code to this:

Waiting Loop

until pgrep -lf "$EXECUABLE"; do sleep 10 done while pgrep -lf "$EXECUTABLE"; do sleep 2 done

Where i set EXECUTABLE to "Valiant" only.

mdeguzis commented 8 years ago

@silelmot , thanks for the catch! You do have a spelling error in the first line, but I get the idea. Let me review this and i'll put this in the template once done.

mdeguzis commented 8 years ago

@silelmot , do you mind submitting a PR against the current template so I what code you wish to add/remove?

silelmot commented 8 years ago

I dont know. My knowledge about linux is really low. Maybe there is a better solution than my code.
Maybe a change at the current code, so that the space in the filename will be ignored, and maybe the exe also.

silelmot commented 8 years ago

Another question (u see i use these scripts a lot) : Is it necessary to close steam? I tried the script without this part, so that wine get closed directly.
This results in a very fast and smooth shutdown. Which is nice

formicsapien commented 8 years ago

Issue: Steam Controller + script

Is there a reason that whenever I launch a game with this it doesn't recognize that a controller is available? I can just bind the KB+M controls, but sometimes I like to have the game interface match my controller, and sometimes I like my control stick to be analog.

mdeguzis commented 8 years ago

@formicsapien , you are dealing with a completely different animal here. The only options here I have used in the past was the joypad control center in Wine ('control' from command line if using an older version), or a pseudo-layer with software like Antimicro. It's difficult to present something that feels 100% natural in these cases. When using joypad config in PlayOnLinux (command in stable version, control panel in latest unstable), it detects the xbox controller, but I haven't been able to make it work. Perhaps it has something to do with the steam user. Maybe @Ryochan7 has an idea why this is the case. Desktop mode carries different running services/applications than the barebones compositor.

mdeguzis commented 8 years ago

@silelmot , made the improvements you mentioned above. Seem to work ok. Testing more tonight.

mdeguzis commented 8 years ago

@formicsapien , I am going to toy around with using xboxdrv at launch-time to mimic an Xbox 360 controller (if enabled in your script). I'll see how this works with one I am currently playing, RAGE. If that works, it will be off by default, but the wiki will note it, or I will enable it for all devices that don't match the device/vendor ID of the Steam Controller (to avoid conflicts).