netbrain / zwift

Easily zwift on linux
The Unlicense
241 stars 27 forks source link

Add support for autologin into Zwift game #18

Closed quietvoid closed 1 year ago

quietvoid commented 1 year ago

Fixes #17.

Todo:

There's also the alternative of switching to https://github.com/quietvoid/runfromprocess-rs but it needs more testing.

quietvoid commented 1 year ago

Current status is that it seems to work just barely with these diffs and the runfromprocess-rs.exe here: runfromprocess-rs.zip (source: https://github.com/quietvoid/runfromprocess-rs)

diff --git a/Dockerfile b/Dockerfile
index 51d151f..a41b331 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -15,4 +15,7 @@ RUN sudo chmod +x /bin/entrypoint
 COPY zwift-auth.sh /bin/zwift-auth
 RUN sudo chmod +x /bin/zwift-auth

+COPY runfromprocess-rs.exe /bin/runfromprocess-rs.exe
+RUN sudo chmod +x /bin/runfromprocess-rs.exe
+
 ENTRYPOINT ["entrypoint"]
diff --git a/entrypoint.sh b/entrypoint.sh
index ddfd9c2..95fd1fe 100644
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -76,17 +76,26 @@ wine64 start ZwiftLauncher.exe

 if [[ -f "/home/user/Zwift/.zwift-credentials" ]]
 then
+       LAUNCHER_PID_HEX=$(winedbg --command "info proc" | grep -P "ZwiftLauncher.exe" | grep -oP "^\s\K.+?(?=\s)")
+       LAUNCHER_PID=$((16#$LAUNCHER_PID_HEX))
+
        echo "authenticating with zwift..."
-       wine64 start RunFromProcess-x64.exe ZwiftLauncher.exe ZwiftApp.exe --token=$(zwift-auth)
+      wine64 start /exec /bin/runfromprocess-rs.exe $LAUNCHER_PID ZwiftApp.exe --token=$(zwift-auth)
+
+       until winedbg --command "info proc" | grep "ZwiftApp.exe" &> /dev/null
+       do
+               echo "Waiting for zwift to start ..."
+               sleep 1
+       done
 else
-       wine64 start RunFromProcess-x64.exe ZwiftLauncher.exe ZwiftApp.exe
-fi
+       wine64 start RunFromProcess-x64.exe ZwiftLauncher.exe ZwiftApp.exe 

-until pgrep ZwiftApp.exe &> /dev/null
-do
-    echo "Waiting for zwift to start ..."
-    sleep 1
-done
+       until pgrep ZwiftApp.exe &> /dev/null
+       do
+               echo "Waiting for zwift to start ..."
+               sleep 1
+       done
+fi

 echo "Killing uneccesary applications"
 pkill ZwiftLauncher

No idea how stable the game actually is afterwards, but the login works.

Maybe wine64 start /exec /bin/runfromprocess-rs.exe also works better. I don't really know why it won't launch without /exec.

netbrain commented 1 year ago

Awesomeness. Should your rust process also be part of this repo? And we'll make a GitHub action to build it and incorporate it into the final image?

On Mon, Sep 4, 2023, 02:19 quietvoid @.***> wrote:

Current status is that it seems to work just barely with these diffs and the runfromprocess-rs.exe here: runfromprocess-rs.zip https://github.com/netbrain/zwift/files/12508296/runfromprocess-rs.zip

diff --git a/Dockerfile b/Dockerfile index 51d151f..a41b331 100644--- a/Dockerfile+++ b/Dockerfile@@ -15,4 +15,7 @@ RUN sudo chmod +x /bin/entrypoint COPY zwift-auth.sh /bin/zwift-auth RUN sudo chmod +x /bin/zwift-auth +COPY runfromprocess-rs.exe /bin/runfromprocess-rs.exe+RUN sudo chmod +x /bin/runfromprocess-rs.exe+ ENTRYPOINT ["entrypoint"]

diff --git a/entrypoint.sh b/entrypoint.sh index ddfd9c2..95fd1fe 100644--- a/entrypoint.sh+++ b/entrypoint.sh@@ -76,17 +76,26 @@ wine64 start ZwiftLauncher.exe

if [[ -f "/home/user/Zwift/.zwift-credentials" ]] then+ LAUNCHER_PID_HEX=$(winedbg --command "info proc" | grep -P "ZwiftLauncher.exe" | grep -oP "^\s\K.+?(?=\s)")+ LAUNCHER_PID=$((16#$LAUNCHER_PID_HEX))+ echo "authenticating with zwift..."- wine64 start RunFromProcess-x64.exe ZwiftLauncher.exe ZwiftApp.exe --token=$(zwift-auth)+ wine64 /bin/runfromprocess-rs.exe $LAUNCHER_PID ZwiftApp.exe --token=$(zwift-auth)++ until winedbg --command "info proc" | grep "ZwiftApp.exe" &> /dev/null+ do+ echo "Waiting for zwift to start ..."+ sleep 1+ done else- wine64 start RunFromProcess-x64.exe ZwiftLauncher.exe ZwiftApp.exe-fi+ wine64 start RunFromProcess-x64.exe ZwiftLauncher.exe ZwiftApp.exe -until pgrep ZwiftApp.exe &> /dev/null-do- echo "Waiting for zwift to start ..."- sleep 1-done+ until pgrep ZwiftApp.exe &> /dev/null+ do+ echo "Waiting for zwift to start ..."+ sleep 1+ done+fi

echo "Killing uneccesary applications" pkill ZwiftLauncher

No idea how stable the game actually is afterwards.

— Reply to this email directly, view it on GitHub https://github.com/netbrain/zwift/pull/18#issuecomment-1704448001, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACTNC4VNO5HKVW4APYPX3DXYUM7LANCNFSM6AAAAAA4JMXBEU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

netbrain commented 1 year ago

Ah yes of course. In that case it needs to be run at every launch.

On Mon, Sep 4, 2023, 13:01 quietvoid @.***> wrote:

@.**** commented on this pull request.

On zwift-auth.sh https://github.com/netbrain/zwift/pull/18#discussion_r1314798195:

The auth token has an expiration though. I don't feel like managing it, so I just went with authenticating on launch.

— Reply to this email directly, view it on GitHub https://github.com/netbrain/zwift/pull/18#discussion_r1314798195, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACTNC2VJQGZHH5RAP7KGJ3XYWYHXANCNFSM6AAAAAA4JMXBEU . You are receiving this because you commented.Message ID: @.***>

quietvoid commented 1 year ago

Did a short 45min test ride and no issue on my side with the changes in the PR (and runfromprocess-rs).

I think it just needs to get rid of the until winedbg --command "info proc" | grep "ZwiftApp.exe" &> /dev/null and just use a fixed sleep time. It doesn't really matter since it's just closing the launcher, but if it's too early the game gets killed as well. So a sleep makes sure the window is actually open.

And then figuring out the build -> copy into container for the new runfromprocess. If it's acceptable I could also make it build in my repo and create a release with the EXE.

But it should be simple to build it, I'm just not sure where it can be done so that the image is updated properly AND that we have a Windows environment. Otherwise it needs to be cross-compiled.

netbrain commented 1 year ago

Have to add curl to the current Dockerfile and then rebuild zwift from scratch i'm afraid. Even if we were to do this in the wine image, this would not change the fact that the docker image has to be rebuilt.

An alternative is to create a new image from a container instance after doing the necessary changes. However i would prefer it to be reproducible by adding all required dependencies (including your rust code) into the original Dockerfile, even if it means we have to download zwift all over again.

Have you tried to build the docker image from scratch using the instructions in the README.

netbrain commented 1 year ago

Regarding the rust code, we can easily store it in a subdirectory of this repo, and have a githubaction that builds it and packages (that builds all from scratch) it into a new image.

quietvoid commented 1 year ago

Have you tried to build the docker image from scratch using the instructions in the README.

Yes, the WebView2 installer URL is a 404. Why did it download anyways? There's a bundled installer that comes with Zwift.

I'll try testing with latest/bundled but it didn't work previously when I tried, although with Wine 8. edit: It didn't work either. At this point it doesn't seem possible to do a clean image build again.

netbrain commented 1 year ago

Would like to help you out with this, but I don't really have the time right now. But I'll assist with what I can.

On Thu, Sep 7, 2023, 13:20 quietvoid @.***> wrote:

Have you tried to build the docker image from scratch using the instructions in the README.

Yes, the WebView2 installer URL is a 404. Why did it download anyways? There's a bundled installer that comes with Zwift.

I'll try testing with latest/bundled but it didn't work previously when I tried, although with Wine 8.

— Reply to this email directly, view it on GitHub https://github.com/netbrain/zwift/pull/18#issuecomment-1709973754, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACTNCZYEDF4MIINE6RLSITXZGUYDANCNFSM6AAAAAA4JMXBEU . You are receiving this because you commented.Message ID: @.***>

quietvoid commented 1 year ago

It would be simple to update the new image and commit it, but I don't think rebuilding from scratch is possible currently. Maybe if there's a way to figure out the same WebView2 version and find the installer for it, maybe it would work.

netbrain commented 1 year ago

Yeah, seems the scratch route has issues: [ERROR] Curl error: [77] 'Problem with the SSL CA cert (path? access rights?)' for: GET https://us-or-rly101.zwift.com/api/telemetry/config [ERROR] Failed to get telemetry config

Seems zwift has it's own curl implementation and it's not using the correct ca authorities within wine.

quietvoid commented 1 year ago

I don't think that's the main issue though. I'm not able to install either MS Edge or the WebView2 runtime at all, so the launcher never launches.

quietvoid commented 1 year ago

Went on Windows, looked up the startup registry key for Zwift and found that the launcher accepts SilentLaunch as argument to start in tray.

I've updated the PR with changes that make building from scratch work.

Tested image build using build-image.sh on my side, the updating starts automatically in the background. It still needs manual intervention for building as you have to click when the Zwift installer asks to download WebView2. Updating should all be automatic.

I think the image size is even smaller with a clean build compared to current.

Just need to add building runfromprocess-rs in the Dockerfile. I'll try to get around to it tomorrow.

netbrain commented 1 year ago

Hope you don't mind, but i made some changes. Added the runfromprocess-rs as a part of the build step.

and improved some general script stuff.

Nice catch on the install flag, seems to work like a charm. Good job!

Only thing were missing now is probably some better documentation on the changes and how to get started using autologin feature in a safe manner (i.e chmod zwift-credendtials to 0700)

Oh, and i've changed the config dir to $HOME/.config/zwift instead of $HOME/.zwift. it's more in the spirit of linux.

And were missing a github action that we can use to create a new release from scratch (i.e. the build-image.sh script)