Compare commits
3 Commits
76d9feb07a
...
33e3eae4cb
Author | SHA1 | Date | |
---|---|---|---|
33e3eae4cb | |||
a79006dc41 | |||
f72e786efa |
14
lmm/cli.py
14
lmm/cli.py
@ -75,9 +75,17 @@ def launch(game: str, profile: str):
|
|||||||
runner.run(game)
|
runner.run(game)
|
||||||
game.wait()
|
game.wait()
|
||||||
|
|
||||||
# Unmount
|
# Unmount (with retries)
|
||||||
for mount in mounts:
|
failed = False
|
||||||
mount.unmount()
|
for retry in range(5):
|
||||||
|
failed = any(not mount.unmount() for mount in mounts)
|
||||||
|
if not failed:
|
||||||
|
break
|
||||||
|
|
||||||
|
print(f"Unmounting failed ({retry +1 }/5). Waiting 3s...")
|
||||||
|
time.sleep(3)
|
||||||
|
if failed:
|
||||||
|
print("Unmounting failed!")
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@ -15,6 +15,10 @@ from lmm.games.ron import (
|
|||||||
GAME_NAME as RON,
|
GAME_NAME as RON,
|
||||||
ReadyOrNotGame,
|
ReadyOrNotGame,
|
||||||
)
|
)
|
||||||
|
from lmm.games.lc import (
|
||||||
|
GAME_NAME as LC,
|
||||||
|
LethalCompanyGame,
|
||||||
|
)
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -34,6 +38,8 @@ def load_game_configs() -> list[Game]:
|
|||||||
BG3: BaldursGate3Game,
|
BG3: BaldursGate3Game,
|
||||||
PDMM: ProjectDivaMegaMixGame,
|
PDMM: ProjectDivaMegaMixGame,
|
||||||
RON: ReadyOrNotGame,
|
RON: ReadyOrNotGame,
|
||||||
|
LC: LethalCompanyGame,
|
||||||
|
|
||||||
}.get(item, None)
|
}.get(item, None)
|
||||||
if game_cls is None:
|
if game_cls is None:
|
||||||
print(f"Unknown game {item}")
|
print(f"Unknown game {item}")
|
||||||
|
93
lmm/games/lc.py
Normal file
93
lmm/games/lc.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from lmm.games.game import ProtonGame
|
||||||
|
from lmm.profile import Profile
|
||||||
|
from lmm.overlayfs import OverlayFSMount
|
||||||
|
from lmm.const import LMM_GAMES_PATH
|
||||||
|
from lmm.runners.base import runner_from_config
|
||||||
|
|
||||||
|
GAME_NAME = "LethalCompany"
|
||||||
|
|
||||||
|
|
||||||
|
class LethalCompanyProfile(Profile):
|
||||||
|
# The names of the directories the the mods directory.
|
||||||
|
mods: list[str]
|
||||||
|
|
||||||
|
def __init__(self, name: str, mods: list[str], **kwargs):
|
||||||
|
super().__init__(GAME_NAME, name, **kwargs)
|
||||||
|
|
||||||
|
self.mods = mods
|
||||||
|
|
||||||
|
def get_mod_names(self) -> list[str]:
|
||||||
|
return self.mods
|
||||||
|
|
||||||
|
|
||||||
|
class LethalCompanyGame(ProtonGame):
|
||||||
|
def __init__(self, profiles: list[LethalCompanyProfile], **kwargs):
|
||||||
|
super().__init__(GAME_NAME, "1966720", profiles, **kwargs)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def installation_path(self) -> Path:
|
||||||
|
return (
|
||||||
|
self.steam_library
|
||||||
|
/ "steamapps/common/Lethal Company"
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def game_executable(self) -> Path:
|
||||||
|
return self.installation_path / "Lethal Company.exe"
|
||||||
|
|
||||||
|
def prepare_overlays(
|
||||||
|
self, profile: LethalCompanyProfile
|
||||||
|
) -> list[OverlayFSMount]:
|
||||||
|
return [
|
||||||
|
OverlayFSMount(
|
||||||
|
upper=self.installation_path,
|
||||||
|
lower=profile.mods,
|
||||||
|
mount=self.installation_path,
|
||||||
|
cd=LMM_GAMES_PATH / self.name,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"profiles": [
|
||||||
|
{
|
||||||
|
"name": profile.name,
|
||||||
|
"mods": [
|
||||||
|
{
|
||||||
|
"name": mod,
|
||||||
|
}
|
||||||
|
for mod in profile.mods
|
||||||
|
],
|
||||||
|
}
|
||||||
|
for profile in self.profiles
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: dict[str, Any]) -> "LethalCompanyGame":
|
||||||
|
profiles = []
|
||||||
|
for profile in data["profiles"]:
|
||||||
|
mods = [mod["name"] for mod in profile["mods"]]
|
||||||
|
|
||||||
|
if "runner" in profile:
|
||||||
|
runner = runner_from_config(profile["runner"])
|
||||||
|
else:
|
||||||
|
runner = None
|
||||||
|
|
||||||
|
profiles.append(
|
||||||
|
LethalCompanyProfile(
|
||||||
|
profile["name"],
|
||||||
|
mods,
|
||||||
|
runner=runner,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
if "default_runner" in data:
|
||||||
|
default_runner = runner_from_config(data["default_runner"])
|
||||||
|
else:
|
||||||
|
default_runner = None
|
||||||
|
|
||||||
|
return LethalCompanyGame(profiles, default_runner=default_runner)
|
@ -102,26 +102,30 @@ class OverlayFSMount:
|
|||||||
self._mounted = True
|
self._mounted = True
|
||||||
return self.mount_path
|
return self.mount_path
|
||||||
|
|
||||||
def unmount(self):
|
def unmount(self) -> bool:
|
||||||
if self._mounted:
|
if self._mounted:
|
||||||
print("Unmounting...")
|
print("Unmounting...")
|
||||||
|
|
||||||
# Remove the mount
|
# Remove the mount
|
||||||
if LMMConfig.use_fuse:
|
if LMMConfig.use_fuse:
|
||||||
run_cmd(
|
returncode = run_cmd(
|
||||||
[
|
[
|
||||||
LMMConfig.fusermount_command,
|
LMMConfig.fusermount_command,
|
||||||
"-u",
|
"-u",
|
||||||
str(self.mount_path),
|
str(self.mount_path),
|
||||||
]
|
]
|
||||||
)
|
) == 0
|
||||||
else:
|
else:
|
||||||
run_sudo_cmd(
|
returncode = run_sudo_cmd(
|
||||||
[
|
[
|
||||||
"umount",
|
"umount",
|
||||||
str(self.mount_path),
|
str(self.mount_path),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if returncode != 0:
|
||||||
|
print("Unmounting failed")
|
||||||
|
return False
|
||||||
|
|
||||||
# Remove the temporary workdir
|
# Remove the temporary workdir
|
||||||
if self.workdir is not None:
|
if self.workdir is not None:
|
||||||
@ -132,6 +136,7 @@ class OverlayFSMount:
|
|||||||
print(f"Failed to clean temporary directory {self.workdir.name}")
|
print(f"Failed to clean temporary directory {self.workdir.name}")
|
||||||
|
|
||||||
self._mounted = False
|
self._mounted = False
|
||||||
|
return True
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.unmount()
|
self.unmount()
|
||||||
|
@ -4,7 +4,8 @@ version = "0.1.0"
|
|||||||
requires-python = ">= 3.10"
|
requires-python = ">= 3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"vdf",
|
"vdf",
|
||||||
"pyyaml"
|
"pyyaml",
|
||||||
|
"click"
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
|
Loading…
Reference in New Issue
Block a user