106 lines
3.0 KiB
Python
106 lines
3.0 KiB
Python
|
import abc
|
||
|
from pathlib import Path
|
||
|
|
||
|
from lmm.runners.runner import Runner
|
||
|
from lmm.games.game import Game
|
||
|
|
||
|
class SteamRuntime(abc.ABC):
|
||
|
def get_run_script(self) -> Path:
|
||
|
raise NotImplementedError()
|
||
|
|
||
|
class SteamSniperRuntime(SteamRuntime):
|
||
|
library: Path
|
||
|
|
||
|
def __init__(self, library: Path):
|
||
|
self.library = library
|
||
|
|
||
|
def get_run_script(self) -> Path:
|
||
|
return self.library / "steamapps" / "common" / "SteamLinuxRuntime_sniper" / "run-in-sniper"
|
||
|
|
||
|
|
||
|
class SteamSoldierRuntime(SteamRuntime):
|
||
|
library: Path
|
||
|
|
||
|
def __init__(self, library: Path):
|
||
|
self.library = library
|
||
|
|
||
|
def get_run_script(self) -> Path:
|
||
|
return self.library / "steamapps" / "common" / "SteamLinuxRuntime_soldier" / "run-in-soldier"
|
||
|
|
||
|
class SteamFlatpakAppIdRunner(Runner):
|
||
|
def __init__(self):
|
||
|
super().__init__("steam.flatpak")
|
||
|
|
||
|
def run(self, game: Game):
|
||
|
assert isinstance(game, ProtonGame)
|
||
|
|
||
|
run_cmd_nonblocking([
|
||
|
"flatpak",
|
||
|
"run",
|
||
|
"com.valvesoftware.Steam",
|
||
|
f"steam://launch/{game.appid}/",
|
||
|
])
|
||
|
|
||
|
class SteamFlatpakProtonRunner(Runner):
|
||
|
# Path to the Proton prefix
|
||
|
compat_data: Path
|
||
|
|
||
|
proton_version: str
|
||
|
|
||
|
runtime: SteamRuntime
|
||
|
|
||
|
game: str
|
||
|
|
||
|
# Launchmode as passed to Proton.
|
||
|
# "waitforexitandrun" | "run"
|
||
|
launchmode: str
|
||
|
|
||
|
def __init__(self, compat_data: Path, runtime: SteamRuntime, proton_version: str, game: str, launchmode: str = "waitforexitandrun"):
|
||
|
self.compat_data = compat_data
|
||
|
self.runtime = runtime
|
||
|
self.game = game
|
||
|
self.proton_version = proton_version
|
||
|
|
||
|
self.launchmode = launchmode
|
||
|
|
||
|
@property
|
||
|
def _steam_install_path(self) -> Path:
|
||
|
return Path.home() / ".steam" / "steam"
|
||
|
|
||
|
def _build_environ(self) -> list[str]:
|
||
|
proton = self._proton_path
|
||
|
return [
|
||
|
f"--env=STEAM_COMPAT_CLIENT_INSTALL_PATH={self._steam_install_path}",
|
||
|
f"--env=STEAM_COMPAT_DATA_PATH={self.compat_data}",
|
||
|
#f"--env=WINEDLLPATH={proton}/files/lib64/wine:{proton}/files/lib/wine",
|
||
|
#f"--env=WINEPREFIX={self.compat_data}/pfx",
|
||
|
#f"--env=SteamGameId=1144200",
|
||
|
#"--env=WINEDLLOVERRIDES=steam.exe=b"
|
||
|
#f"--env=WINEDEBUG=-all",
|
||
|
]
|
||
|
|
||
|
@property
|
||
|
def _proton_path(self) -> Path:
|
||
|
return Path.home() / "data" / "Steam" / "compatibilitytools.d" / self.proton_version
|
||
|
|
||
|
def _build_launch_command(self) -> str:
|
||
|
command = [
|
||
|
str(self.runtime.get_run_script()),
|
||
|
str(self._proton_path / "proton"),
|
||
|
self.launchmode,
|
||
|
f"'{self.game}'",
|
||
|
]
|
||
|
commandline = " ".join(command)
|
||
|
return commandline
|
||
|
|
||
|
def run(self):
|
||
|
run_cmd_shell(" ".join([
|
||
|
"flatpak",
|
||
|
"run",
|
||
|
"--command=bash",
|
||
|
*self._build_environ(),
|
||
|
"com.valvesoftware.Steam",
|
||
|
"-c",
|
||
|
f'"{self._build_launch_command()}"',
|
||
|
]))
|