detect proper game dir, use dxvk instead of d9vk, and replace os.path with pathlib

This commit is contained in:
Izalia Mae 2021-05-01 22:23:16 -04:00
parent 1ea42c1bd6
commit 25d2901502
3 changed files with 81 additions and 42 deletions

View file

@ -6,12 +6,12 @@ PT won't run in WINE or Proton without some extra steps, so this script simplifi
* Steam
* Wine (tested with 4.0)
* Python 3.6.0 (tested with 3.8.0)
* Python 3.6.0+ (tested with 3.8.0 and 3.9.2)
## Installation
* Run setup.sh or copy run.py to $HOME/.steam/steam/steamapps/common/Project Torque/run.py
* Set run command in Steam: Project Torque > Right-click > Properties > Set Launcher Options > ./run.py %command%
* Run setup.sh or copy run.py to your PT directory (usually `$HOME/.steam/steam/steamapps/common/Project Torque/run.py`)
* Set run command in Steam: Project Torque > Right-click > Properties > Set Launcher Options > `python3 run.py %command%`
## Usage

109
run.py
View file

@ -1,87 +1,122 @@
#!/usr/bin/env python3
'''
Project Torque Linux Launcher
Project Torque Linux Launcher v0.2
by Izalia Mae (https://barkshark.xyz/izalia)
https://git.barkshark.xyz/izaliamae/pt-launcher
Installation:
- Copy to ~/.steam/steam/steamapps/common/Project Torque/run.py
- Steam:
- Project Torque > Right-click > Properties > Set Launcher Options > ./run.py %command%
- Project Torque > Right-click > Properties > Launch Options > ./run.py %command%
To run the script in a terminal, set launch options to: konsole --hold -e ./run.py %command%
'''
import os
import sys
import urllib.request
import tarfile
import shutil
import os, shutil, subprocess, sys, tarfile
env = os.environ
from pathlib import Path
from os import environ as env
from urllib.request import urlopen
script_path = os.path.abspath(os.path.dirname(__file__))
home = env.get('HOME')
d9vk_ver = '0.40.1'
pt_path = script_path if os.path.isfile(f'{script_path}/ProjectTorque.exe') else f'{home}/.steam/steam/steamapps/common/Project Torque'
wprefix = f'{home}/.local/share/wineprefix/project-torque'
wtricks = f'{home}/.local/bin/winetricks'
script_path = Path(__file__).parent
home = Path('~').expanduser()
pt_path = script_path if script_path.joinpath('ProjectTorque.exe').is_file() else Path(sys.argv[-1]).parent
wprefix = home.joinpath('.local/share/wineprefix/project-torque')
wtricks = home.joinpath('.local/bin/winetricks')
command = f"/usr/bin/env WINEPREFIX={wprefix} wine '{pt_path}/ProjectTorque.exe'"
lsb_proc = subprocess.Popen(['lsb_release', '-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = lsb_proc.communicate()
for line in out.decode().split('\n')[1:]:
try:
k,v = line.split(':\t')
debian_buster = k.lower() == 'codename' and v.lower() == 'buster'
except ValueError:
debian_buster
dxvk_ver = '0.40.1' if debian_buster else '1.8.1'
dxvk_cache = home.joinpath(f'.cache/dxvk/dxvk-{dxvk_ver}')
dxvk_tar = dxvk_cache.joinpath(f'dxvk-{dxvk_ver}.tar.gz')
def setup():
try:
os.makedirs(wprefix, exist_ok=True)
os.makedirs(f'{home}/.local/bin', exist_ok=True)
wprefix.mkdir(exist_ok=True, parents=True)
wtricks.parent.mkdir(exist_ok=True, parents=True)
except Exception as e:
print(f'Error when trying to create necessary directories: {e}')
sys.exit()
return
if not os.path.isfile(wtricks):
if not wtricks.is_file():
print(f'Downloading winetricks to {wtricks}')
url = 'https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks'
with urllib.request.urlopen(url) as response, open(wtricks, 'wb') as out_file:
with urlopen(url) as response, wtricks.open('wb') as out_file:
shutil.copyfileobj(response, out_file)
os.system(f'chmod +x {wtricks}')
if not os.path.isfile(f'{wprefix}/setup'):
if not wprefix.joinpath('setup').is_file():
print(f'Running winetricks')
os.system(f'/usr/bin/env W_OPT_UNATTENDED=1 WINEPREFIX={wprefix} WINEARCH=win32 LD_PRELOAD= {wtricks} tahoma dotnet35sp1 d3dx9 d3dcompiler_43')
tar = f'{home}/.cache/d9vk/d9vk-{d9vk_ver}.tar.gz'
dxvk_tar = home.joinpath(f'.cache/dxvk/dxvk-{dxvk_ver}.tar.gz')
if not os.path.isfile(tar):
print('Downloading d9vk')
if not dxvk_tar.is_file():
print(f'Downloading {"d9vk" if debian_buster else "dxvk"}')
os.makedirs(f'{home}/.cache/d9vk', exist_ok=True)
home.joinpath('.cache/dxvk').mkdir(exist_ok=True, parents=True)
url = f'https://github.com/Joshua-Ashton/d9vk/releases/download/{d9vk_ver}/d9vk-{d9vk_ver}.tar.gz'
if debian_buster:
url = f'https://github.com/Joshua-Ashton/d9vk/releases/download/0.40.1/d9vk-0.40.1.tar.gz'
with urllib.request.urlopen(url) as response, open(tar, 'wb') as out_file:
else:
url = f'https://github.com/doitsujin/dxvk/releases/download/v{dxvk_ver}/dxvk-{dxvk_ver}.tar.gz'
with urlopen(url) as response, dxvk_tar.open('wb') as out_file:
shutil.copyfileobj(response, out_file)
if not os.path.isdir(f'{home}/.cache/d9vk/d9vk-{d9vk_ver}'):
print('Installing d9vk to prefix')
print(f'Installing {"d9vk" if debian_buster else "dxvk"} to prefix')
d9vk = tarfile.open(tar)
d9vk.extractall(f'{home}/.cache/d9vk/')
dxvk = tarfile.open(dxvk_tar)
dxvk.extractall(home.joinpath('.cache/dxvk/'))
os.system(f'/usr/bin/env LD_PRELOAD= WINEPREFIX={wprefix} {home}/.cache/d9vk/d9vk-{d9vk_ver}/setup_dxvk.sh install')
## I tried with esync, but I think it causes more crashes. Will have to test more
#if os.system(f'/usr/bin/env LD_PRELOAD= WINEESYNC=1 WINEPREFIX={wprefix} {dxvk_cache.joinpath("setup_dxvk.sh")} install'):
os.system(f'touch {wprefix}/setup')
print('Setup done!')
if os.system(f'/usr/bin/env LD_PRELOAD= WINEPREFIX={wprefix} {dxvk_cache.joinpath("setup_dxvk.sh")} install'):
print('Failed to install dxvk')
return
os.system
## I tried using regedit to import a reg file, but it didn't work for some reason, so here's a quick hack
## This just prevents steam from trying to install dotnet3.5 every time it starts
if 'common' in str(pt_path):
sysreg = Path(str(pt_path).lower().split('common')[0]).joinpath('compatdata/1112400/pfx/system.reg')
with sysreg.open('ab') as fd, script_path.joinpath('workaround.reg').open('rb') as reg:
fd.write(reg.read())
wprefix.joinpath('setup').touch(exist_ok=True)
print('Setup done!')
return True
if __name__ == '__main__':
try:
if not os.path.isdir(pt_path):
if not pt_path.is_dir():
print('Cannot find the PT directory. Did you install the game?')
sys.exit()
sys.exit(1)
setup()
if not pt_path.joinpath('ProjectTorque.exe').exists():
print(f'Executable missing. Is this the right directory? {pt_path}')
sys.exit(1)
if not setup():
print('Setup did not finish properly')
sys.exit(1)
print(f'Running: {command}')

8
setup.sh Normal file → Executable file
View file

@ -1,3 +1,7 @@
#!/bin/sh
#!/usr/bin/env bash
cp run.py $HOME/.steam/steam/steamapps/common/Project\ Torque/
if [ -d "$HOME/.steam/steam/steamapps/common/Project Torque" ]; then
ln -sr run.py $HOME/.steam/steam/steamapps/common/Project\ Torque/
else
echo "Cannot find Project Torque directory. If your steam folder is in a different location, you'll have to copy 'run.py' to the Project Torque directory manually"
fi