linux-mod-manager/lmm/runners/steam.py

141 lines
3.4 KiB
Python
Raw Normal View History

2023-12-02 16:45:16 +00:00
import abc
from pathlib import Path
from lmm.runners.runner import Runner
from lmm.games.game import Game
2023-12-02 16:46:48 +00:00
2023-12-02 16:45:16 +00:00
class SteamRuntime(abc.ABC):
def get_run_script(self) -> Path:
raise NotImplementedError()
2023-12-02 16:46:48 +00:00
2023-12-02 16:45:16 +00:00
class SteamSniperRuntime(SteamRuntime):
library: Path
def __init__(self, library: Path):
self.library = library
def get_run_script(self) -> Path:
2023-12-02 16:46:48 +00:00
return (
self.library
/ "steamapps"
/ "common"
/ "SteamLinuxRuntime_sniper"
/ "run-in-sniper"
)
2023-12-02 16:45:16 +00:00
class SteamSoldierRuntime(SteamRuntime):
library: Path
def __init__(self, library: Path):
self.library = library
def get_run_script(self) -> Path:
2023-12-02 16:46:48 +00:00
return (
self.library
/ "steamapps"
/ "common"
/ "SteamLinuxRuntime_soldier"
/ "run-in-soldier"
)
2023-12-02 16:45:16 +00:00
class SteamFlatpakAppIdRunner(Runner):
def __init__(self):
super().__init__("steam.flatpak")
def run(self, game: Game):
assert isinstance(game, ProtonGame)
2023-12-02 16:46:48 +00:00
run_cmd_nonblocking(
[
"flatpak",
"run",
"com.valvesoftware.Steam",
f"steam://launch/{game.appid}/",
]
)
2023-12-02 16:45:16 +00:00
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
2023-12-02 16:46:48 +00:00
def __init__(
self,
compat_data: Path,
runtime: SteamRuntime,
proton_version: str,
game: str,
launchmode: str = "waitforexitandrun",
):
2023-12-02 16:45:16 +00:00
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}",
2023-12-02 16:46:48 +00:00
# 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",
2023-12-02 16:45:16 +00:00
]
@property
def _proton_path(self) -> Path:
2023-12-02 16:46:48 +00:00
return (
Path.home()
/ "data"
/ "Steam"
/ "compatibilitytools.d"
/ self.proton_version
)
2023-12-02 16:45:16 +00:00
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):
2023-12-02 16:46:48 +00:00
run_cmd_shell(
" ".join(
[
"flatpak",
"run",
"--command=bash",
*self._build_environ(),
"com.valvesoftware.Steam",
"-c",
f'"{self._build_launch_command()}"',
]
)
)