Initial commit

This commit is contained in:
2023-12-02 17:45:16 +01:00
commit d352e70956
18 changed files with 1074 additions and 0 deletions

15
lmm/runners/base.py Normal file
View File

@@ -0,0 +1,15 @@
import abc
from pathlib import Path
from typing import Any, Optional
from lmm.cmd import run_cmd_nonblocking
from lmm.games.game import Game, ProtonGame
from lmm.runners.runner import Runner
from lmm.runners.steam import SteamFlatpakAppIdRunner
def runner_from_config(data: dict[str, Any]) -> Optional[Runner]:
match data["type"]:
case "steam.flatpak":
return SteamFlatpakAppIdRunner()
case _:
return None

13
lmm/runners/runner.py Normal file
View File

@@ -0,0 +1,13 @@
import abc
from lmm.games.game import Game
class Runner(abc.ABC):
# Type identifier of the runner.
runner_type: str
def __init__(self, runner_type: str):
self.runner_type = runner_type
def run(self, game: Game):
raise NotImplementedError()

105
lmm/runners/steam.py Normal file
View File

@@ -0,0 +1,105 @@
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()}"',
]))