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

protontricks: init at 1.2.3 #64705

Merged
merged 3 commits into from Jul 20, 2019
Merged

protontricks: init at 1.2.3 #64705

merged 3 commits into from Jul 20, 2019

Conversation

kira-bruneau
Copy link
Contributor

@kira-bruneau kira-bruneau commented Jul 13, 2019

Motivation for this change

This adds the protontricks package with required dependencies: #61193.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@kira-bruneau
Copy link
Contributor Author

kira-bruneau commented Jul 13, 2019

@aanderse I see that this was already assigned to you, but I wasn't sure of your progress. Does this seem like the right approach?

@aanderse
Copy link
Member

@MetaDark Thanks for doing this! I assigned the issue to myself because I eventually have a need for it so eventually I would have got around to it... but you did first! I will review and test this tonight.

Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nuff said @aanderse 😄 , reviewed the python bit.

pkgs/development/python-modules/vdf/default.nix Outdated Show resolved Hide resolved
pkgs/tools/package-management/protontricks/default.nix Outdated Show resolved Hide resolved
@aanderse
Copy link
Member

@MetaDark I built & installed protontricks on my stable NixOS system, ran the program, selected a game, and got the following error:

~> protontricks --gui
Traceback (most recent call last):
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/bin/.protontricks-wrapped", line 11, in <module>
    sys.exit(main())
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/lib/python3.7/site-packages/protontricks/cli.py", line 178, in main
    steam_path=steam_path, steam_apps=steam_apps, appid=steam_app.appid
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/lib/python3.7/site-packages/protontricks/steam.py", line 356, in find_proton_app
    steam_path=steam_path, steam_apps=steam_apps, appid=appid)
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/lib/python3.7/site-packages/protontricks/steam.py", line 317, in find_steam_proton_app
    proton_appid = re.search(appid_regex, appinfo).group(2)
AttributeError: 'NoneType' object has no attribute 'group'

I have never used protontricks before so I'm not sure where things went wrong. On the plus side when I launched protontricks it showed me my steam library which is using proton.

Any thoughts?

@kira-bruneau
Copy link
Contributor Author

kira-bruneau commented Jul 14, 2019

@MetaDark I built & installed protontricks on my stable NixOS system, ran the program, selected a game, and got the following error:

~> protontricks --gui
Traceback (most recent call last):
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/bin/.protontricks-wrapped", line 11, in <module>
    sys.exit(main())
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/lib/python3.7/site-packages/protontricks/cli.py", line 178, in main
    steam_path=steam_path, steam_apps=steam_apps, appid=steam_app.appid
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/lib/python3.7/site-packages/protontricks/steam.py", line 356, in find_proton_app
    steam_path=steam_path, steam_apps=steam_apps, appid=appid)
  File "/nix/store/6slrbp5hb8ijd5gv7fb6k80jmp8g3176-protontricks-1.2.2/lib/python3.7/site-packages/protontricks/steam.py", line 317, in find_steam_proton_app
    proton_appid = re.search(appid_regex, appinfo).group(2)
AttributeError: 'NoneType' object has no attribute 'group'

I have never used protontricks before so I'm not sure where things went wrong. On the plus side when I launched protontricks it showed me my steam library which is using proton.

Any thoughts?

Hmm I haven't run into that issue before. It looks like it's failing to find the proton app for the given app id. It first looks in ~/.local/share/Steam/config/config.vdf and then tries to read from ~/.local/share/Steam/appcache/appinfo.vdf. It seems to be failing there because a regex on appinfo returns no results.

What is the output if you try to run the following?

#!/usr/bin/env nix-shell
#!nix-shell -i python '<nixpkgs>' -A protontricks

import vdf
import os
from pathlib import Path
from pprint import pprint

config_file = os.path.join(Path.home(), '.local/share/Steam/config/config.vdf')

with open(config_file) as f:
    vdf_data = vdf.load(f)
    pprint(vdf_data["InstallConfigStore"]["Software"]["Valve"]["Steam"].get("ToolMapping"))
    pprint(vdf_data["InstallConfigStore"]["Software"]["Valve"]["Steam"].get("CompatToolMapping"))

@aanderse
Copy link
Member

@MetaDark Thanks for looking into this. I should note that I have a second 'steam library' setup so all my games are installed into /opt/steamapps. I tried moving a game into the standard library location but had the same results.

Output of your script:

{'0': {}}
{'0': {'Priority': '75', 'config': '', 'name': 'proton_316_beta'},
 '2147483649': {'Priority': '250', 'config': '', 'name': 'proton_316_beta'},
 '2147483650': {'Priority': '250', 'config': '', 'name': 'proton_316_beta'},
 '2147483652': {'Priority': '250', 'config': '', 'name': 'proton_316_beta'},
 '405310': {'Priority': '250', 'config': '', 'name': ''}}

@kira-bruneau
Copy link
Contributor Author

kira-bruneau commented Jul 14, 2019

@aanderse No problem 😊. If you run strings on ~/.local/share/Steam/appcache/appinfo.vdf, do you see proton_316_beta in there at all? If you do, I'm thinking that the magic number protontricks uses in the regex might be different on your install.

This script should pull out the magic number, if that's the case:

#!/usr/bin/env nix-shell
#!nix-shell -i python '<nixpkgs>' -A protontricks

import binascii
import os
import re
import struct
import vdf
from pathlib import Path

tool_mapping_name = 'proton_316_beta'

steam_path = os.path.join(Path.home(), '.local/share/Steam/')
appinfo_path = os.path.join(steam_path, 'appcache/appinfo.vdf')

with open(appinfo_path, 'rb') as f:
    vdf_data = f.read().hex()
    appid_regex = '({0})(.{{16}})(.{{8}})'.format(bytes(tool_mapping_name, 'utf-8').hex())

    magic = None
    for match in re.finditer(appid_regex, vdf_data):
        magic = match.group(2)
        app_id = struct.unpack('<I', binascii.unhexlify(match.group(3)))[0]
        print('name: {}, app_id: {}, magic: {}'.format(tool_mapping_name, app_id, magic))

    if magic is None:
        print("Failed to find '{}' in appinfo".format(tool_mapping_name))

The magic number used in the regex is: 0002617070696400

@aanderse
Copy link
Member

aanderse commented Jul 14, 2019

@MetaDark

$ strings ~/.local/share/Steam/appcache/appinfo.vdf | grep proton_316_beta
proton_316_beta

And the results of script: name: proton_316_beta, app_id: 926113646, magic: 00080070726f746f

@kira-bruneau
Copy link
Contributor Author

@aanderse Hmm yep, it looks like protontricks needs to be fixed upstream then. It really should be using the binary api for vdf rather than using regex's to find this information.

@kira-bruneau
Copy link
Contributor Author

kira-bruneau commented Jul 14, 2019

@aanderse If you still want to try it out, you can use this patch in the nix expression:

From 0bf70a56b6a8597a6e30e9dbf7ef061f4bc17936 Mon Sep 17 00:00:00 2001
From: MetaDark <kira.bruneau@gmail.com>
Date: Sun, 14 Jul 2019 13:52:48 -0400
Subject: [PATCH] custom magic number

---
 src/protontricks/steam.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/protontricks/steam.py b/src/protontricks/steam.py
index d70c416..eabcb96 100644
--- a/src/protontricks/steam.py
+++ b/src/protontricks/steam.py
@@ -310,7 +310,7 @@ def find_steam_proton_app(steam_path, steam_apps, appid=None):
     # ```
     # proton_316_beta..appid.
     # ```
-    appid_regex = "({name_ascii}0002617070696400)([a-z0-9]{{8}})".format(
+    appid_regex = "({name_ascii}00080070726f746f)([a-z0-9]{{8}})".format(
         name_ascii=str(binascii.hexlify(bytes(name, "utf-8")), "utf-8")
     )
     # The second group contains the App ID as a 32-bit integer in little-endian
-- 
2.22.0

@aanderse
Copy link
Member

aanderse commented Jul 15, 2019

@MetaDark Well one step closer. When I apply the patch you said I select a game and now get this:

~> protontricks --gui
protontricks (ERROR): Active Proton installation could not be found automatically.
Proton installation could not be found!

I appreciate all the help so far. Hopefully I'll find some time to dig into this...

@Matoking
Copy link
Contributor

I've pushed a fix to protontricks' repo in the appinfo_parse branch. The fix should parse the appinfo.vdf file properly based on the vdf Python library developer's comment here.

The fix is working for me, but I'd like to hear if it's working on other environments besides my own first. If that's the case, I'll look into merging it into master soon. :)

@aanderse
Copy link
Member

@Matoking Thanks for taking a look at this. I just built protontricks against your appinfo_parse branch and was able to launch the program and select a game, but now I get a slightly different error:

~> protontricks --gui
protontricks (ERROR): Could not find Proton's App ID from appinfo.vdf
protontricks (ERROR): Active Proton installation could not be found automatically.
Proton installation could not be found!

Any ideas?

@Matoking
Copy link
Contributor

Matoking commented Jul 16, 2019

@Matoking Thanks for taking a look at this. I just built protontricks against your appinfo_parse branch and was able to launch the program and select a game, but now I get a slightly different error:

~> protontricks --gui
protontricks (ERROR): Could not find Proton's App ID from appinfo.vdf
protontricks (ERROR): Active Proton installation could not be found automatically.
Proton installation could not be found!

Any ideas?

I pushed another update to the appinfo_parse branch at Matoking/protontricks@e58b094. With some luck, it should work.

And if that doesn't work, another option is to upload the appinfo.vdf file somewhere and see what's wrong with it. It seems to contain information about all the games affiliated with the currently logged in Steam user, including the SteamPlay manifests which contain the "compat tool name to app ID" mapping Protontricks needs.

@aanderse
Copy link
Member

@Matoking Unfortunately this did not work. I have sent you an e-mail including my appinfo.vdf file. Please let me know if there is anything else I can do or provide. Thank you for your work on this.

@Matoking
Copy link
Contributor

@aanderse

Hi, I received your appinfo.vdf and made another commit to the branch at Matoking/protontricks@1f25ec0.

Third time's hopefully the charm, but if that still doesn't work, could you check your Steam configuration file at ~/.steam/root/config/config.vdf, find the section named CompatToolMapping or ToolMapping and check what name entries you can find under it. For example, I have these entries in my own file:

"0"
{
    "name"		"proton_42"
    "config"		""
    "Priority"		"75"
}
"2147483652"
{
    "name"		"proton_316_beta"
    "config"		""
    "Priority"		"250"
}
"2147483653"
{
    "name"		"proton_316_beta"
    "config"		""
    "Priority"		"250"
}
"258180"
{
    "name"		"proton_37"
    "config"		""
    "Priority"		"250"
}

@aanderse
Copy link
Member

@MetaDark and @Matoking I can't express how much I appreciate your help on this. Your latest revision solves the problem entirely and allows me to successfully run the command protontricks 214510 d3dx9_41 😄

My son and I are about to finish our most recent LEGO game so this fix couldn't have come at a better time!

@Matoking
Copy link
Contributor

@aanderse Thanks for your help in solving this bug. 👍

I've pushed out a new release 1.2.3 with this bug fix. If this gets accepted into NixOS' package repository, I'd be happy to add the package under the list of unofficial packages in the main repo.

@aanderse
Copy link
Member

@MetaDark When you get a chance to bump this to version 1.2.3 please also squash all but the first commits into one.

Thanks again to everyone!

@kira-bruneau
Copy link
Contributor Author

kira-bruneau commented Jul 18, 2019

Just pushed the changes! Thank you @aanderse for testing and reviewing the package and thank you @Matoking for pushing a new fix so quickly 😄

@aanderse
Copy link
Member

aanderse commented Jul 18, 2019

@GrahamcOfBorg build protontricks

@kira-bruneau
Copy link
Contributor Author

kira-bruneau commented Jul 18, 2019

@aanderse I don't think the build will succeed if it's running it directly from master. I had to set gstreamerSupport = false in pkgs/top-level/wine-packages.nix to work around a build issue with qt5.

@kira-bruneau
Copy link
Contributor Author

@aanderse I managed to work around the build issue by ensuring that winetricks depends on the same minimal build of wine that protontricks depends on. This has the added benefit of reducing the closure size.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@aanderse aanderse changed the title protontricks: init at 1.2.2 protontricks: init at 1.2.3 Jul 20, 2019
@aanderse aanderse merged commit 1af592d into NixOS:master Jul 20, 2019
@kira-bruneau kira-bruneau deleted the protontricks branch July 20, 2019 15:24
@kira-bruneau kira-bruneau mentioned this pull request Jul 5, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants