Skip to content

Commit 28613e3

Browse files
Merge pull request #277 from Root-Core/trivial_changes
Refactor: some "trivial" changes
2 parents 82fcd13 + a2158b2 commit 28613e3

14 files changed

+279
-226
lines changed

.github/scripts/steam_client.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,60 @@
88
from steam.utils.proto import proto_to_dict
99
from typing import Any
1010

11+
class Steam:
12+
"""Minimal implementation of the SteamClient package that allows app id validation"""
1113

12-
class Steam: # noqa: D101
13-
def __init__(self) -> None: # noqa: D107
14+
def __init__(self) -> None:
15+
"""Setup SteamClient and it's events
16+
17+
Raises:
18+
ValueError: When the SteamClient fires it's "error" event
19+
20+
"""
1421
self.logged_on_once = False
1522

1623
self.steam = client = SteamClient()
1724

18-
@client.on('error')
25+
# FIXME: pyright outputs 'error: Object of type "None" cannot be called (reportOptionalCall)'
26+
@client.on(SteamClient.EVENT_ERROR) # pyright: ignore (reportOptionalCall)
1927
def handle_error(result: EResult) -> None:
2028
raise ValueError(f'Steam error: {repr(result)}')
2129

22-
@client.on('connected')
30+
@client.on(SteamClient.EVENT_CONNECTED) # pyright: ignore (reportOptionalCall)
2331
def handle_connected() -> None:
2432
print(f'Connected to {client.current_server_addr}', file=sys.stderr)
2533

26-
@client.on('channel_secured')
34+
@client.on(SteamClient.EVENT_CHANNEL_SECURED) # pyright: ignore (reportOptionalCall)
2735
def send_login() -> None:
2836
if self.logged_on_once and self.steam.relogin_available:
2937
self.steam.relogin()
3038

31-
@client.on('disconnected')
39+
@client.on(SteamClient.EVENT_DISCONNECTED) # pyright: ignore (reportOptionalCall)
3240
def handle_disconnect() -> None:
3341
print('Steam disconnected', file=sys.stderr)
3442
if self.logged_on_once:
3543
print('Reconnecting...', file=sys.stderr)
3644
client.reconnect(maxdelay=30)
3745

38-
@client.on('logged_on')
46+
@client.on(SteamClient.EVENT_LOGGED_ON) # pyright: ignore (reportOptionalCall)
3947
def handle_after_logon() -> None:
4048
self.logged_on_once = True
4149

4250
client.anonymous_login()
4351

52+
4453
def get_valid_appids(self, appids: set[int]) -> set[int]:
4554
"""Queries Steam for the specified appids.
4655
47-
If an appid doesn't exist, it won't be in the response.
56+
Args:
57+
appids (set[int]): The app ids that should be validated
58+
59+
Raises:
60+
ValueError: When the response is empty / unexpected
61+
62+
Returns:
63+
set[int]: Only valid app ids will be returned
4864
49-
Raises a ValueError if Steam returns unexpected data
5065
"""
5166
# https://github.com/SteamRE/SteamKit/blob/master/SteamKit2/SteamKit2/Base/Generated/SteamMsgClientServerAppInfo.cs#L331
5267
resp = self.steam.send_job_and_wait(

fix.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from functools import lru_cache
99
from importlib import import_module
1010

11+
from .util import ProtonVersion
1112
from .config import config
1213
from .checks import run_checks
1314
from .logger import log
@@ -184,5 +185,6 @@ def main() -> None:
184185
log.debug('Not running protonfixes for setup runs')
185186
return
186187

187-
log.info('Running protonfixes')
188+
version = ProtonVersion.from_version_file()
189+
log.info(f'Running protonfixes on "{version.version_name}", build at {version.build_date}.')
188190
run_fix(get_game_id())

gamefixes-steam/105400.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def main() -> None:
2323
if os.path.exists(dirpath):
2424
shutil.rmtree(dirpath)
2525
else:
26-
log(f"Path '{dirpath}' could not be found")
26+
log.info(f"Path '{dirpath}' could not be found")

gamefixes-steam/1449280.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def main() -> None:
1313
try:
1414
Path(save_dir).mkdir(parents=True, exist_ok=True)
1515
except OSError as e:
16-
log(f"Not able to make the settings directory at '{save_dir}': {e}")
16+
log.warn(f"Not able to make the settings directory at '{save_dir}': {e}")

gamefixes-steam/1873170.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Cease to Breathe
2-
Replace included nwjs(0.71) wich doesn't work with 0.86
2+
Replace included nwjs (0.71) - which doesn't work - with 0.86
33
Fix cursor hitbox (set frame=false in package.json)
44
Updated from 0.85 that didn't display custom cursors.
55
"""

gamefixes-steam/22330.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import os
1414

15-
from dataclasses import dataclass
1615
from protonfixes import util
1716

1817

@@ -24,19 +23,11 @@ def main_with_id(game_id: str) -> None:
2423

2524
# Run script extender if it exists.
2625
mapping = get_redirect_name(game_id)
27-
if os.path.isfile(mapping.to_name):
28-
util.replace_command(mapping.from_name, mapping.to_name)
26+
if os.path.isfile(mapping.to_value):
27+
util.replace_command(mapping.from_value, mapping.to_value)
2928

3029

31-
@dataclass
32-
class Redirect:
33-
"""Used for replacements"""
34-
35-
from_name: str
36-
to_name: str
37-
38-
39-
def get_redirect_name(game_id: str) -> Redirect:
30+
def get_redirect_name(game_id: str) -> util.ReplaceType:
4031
"""Mapping for SteamID -> script extender replacements"""
4132
mapping = {
4233
'22380': ('FalloutNV.exe', 'nvse_loader.exe'), # Fallout New Vegas
@@ -51,4 +42,4 @@ def get_redirect_name(game_id: str) -> Redirect:
5142
'489830': ('SkyrimSELauncher.exe', 'skse64_loader.exe'), # Skyrim SE
5243
'1716740': ('Starfield.exe', 'sfse_loader.exe'), # Starfield
5344
}.get(game_id, ('', ''))
54-
return Redirect(*mapping)
45+
return util.ReplaceType(*mapping)

gamefixes-steam/2475980.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
1-
"""Gobliiins 5
1+
"""Gobliiins 5 (and Demo - 2505910)
22
Setup doesn't work and language is default to french
33
"""
44

5-
import os
6-
import sys
7-
import subprocess
8-
import glob
95
from protonfixes import util
106

117

12-
def main() -> None:
13-
if sys.argv[2].find('winsetup') != -1:
14-
os.chdir(sys.argv[2][-29:-13])
8+
def main_with_id(game_id: str) -> None:
9+
"""The game consists of 4 parts, that are located in their own folder
10+
They each have a separate config, that needs to be patched
1511
16-
install_dir = glob.escape(util.get_game_install_path())
17-
with open(
18-
os.path.join(install_dir, 'Gobliiins5-Part4/acsetup.cfg'), encoding='utf-8'
19-
) as f:
20-
if 'Linear' not in f.read():
21-
for i in range(1, 5):
22-
subprocess.call(
23-
[
24-
f"sed -i 's/filter=stdscale/filter=Linear/' {install_dir}/Gobliiins5-Part{i}/acsetup.cfg"
25-
],
26-
shell=True,
27-
)
28-
subprocess.call(
29-
[
30-
f"sed -i 's/translation.*/translation=English/' {install_dir}/Gobliiins5-Part{i}/acsetup.cfg"
31-
],
32-
shell=True,
33-
)
12+
The demo launches from it's install directory and doesn't need a subfolder
13+
"""
14+
cfg_str = """
15+
[language]
16+
translation=English
17+
18+
[graphics]
19+
filter=Linear
20+
"""
21+
22+
# Demo
23+
if game_id == '2505910':
24+
util.set_ini_options(cfg_str, 'acsetup.cfg', 'utf-8', 'game')#
25+
return
26+
27+
# Full
28+
for i in range(1, 5):
29+
util.set_ini_options(cfg_str, f'Gobliiins5-Part{i}/acsetup.cfg', 'utf-8', 'game')

gamefixes-steam/2505910.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2475980.py

gamefixes-steam/294700.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
"""Game fix for Putt-Putt: Pep's Birthday Surprise"""
22

3-
import os
43
from protonfixes import util
54

65

7-
# Putt-Putt: PBS doesn't run unless there is a CD-ROM drive attached.
86
def main() -> None:
9-
dosdevice = os.path.join(util.protonprefix(), 'dosdevices/r:')
10-
if not os.path.exists(dosdevice):
11-
os.symlink('/tmp', dosdevice) # create symlink for dosdevices
7+
"""The game doesn't run unless there is a CD-ROM drive attached."""
8+
util.create_dos_device()
129

10+
# sets up ID? exported from regedit
1311
util.regedit_add(
1412
'HKLM\\System\\MountedDevices',
1513
'\\??\\Volume{00000000-0000-0000-0000-000000000052}',
1614
'REG_BINARY',
1715
'2f746d7000',
18-
) # sets up ID? exported from regedit
16+
)
17+
18+
# sets up dosdevice? exported from regedit
1919
util.regedit_add(
2020
'HKLM\\System\\MountedDevices',
2121
'\\DosDevices\\R:',
2222
'REG_BINARY',
2323
'5c005c002e005c0064003a000000',
24-
) # sets up dosdevice? exported from regedit
25-
util.regedit_add(
26-
'HKLM\\Software\\Wine\\Drives', 'r:', 'REG_SZ', 'cdrom', True
27-
) # designate drive as CD-ROM, requires 64-bit access
24+
)

gamefixes-steam/39500.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""Game fix for Gothic 3"""
1+
"""Game fix for Gothic 3 (and Forsaken Gods Enhanced Edition)"""
22

3-
import os
43
from protonfixes import util
54

65

@@ -12,4 +11,4 @@ def main() -> None:
1211
FpS.Max=0
1312
"""
1413

15-
util.set_ini_options(game_opts, os.path.join('Ini', 'ge3.ini'), 'cp1251', 'game')
14+
util.set_ini_options(game_opts, 'Ini/ge3.ini', 'cp1251', 'game')

0 commit comments

Comments
 (0)