Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Fixed and enforced types + logger class rewrite #201

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions .github/scripts/check_verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import re
import subprocess

from glob import iglob
from pathlib import Path
from tempfile import mkdtemp
from collections.abc import Generator

# 'gui' is a virtual verb for opening the Winetricks GUI
# 'vd=1280x720' is a setting for the virtual desktop and valid
whitelist_verbs = {'gui', 'vd=1280x720'}


def extract_verbs_from_glob(path_glob: iglob) -> set[str]:
def extract_verbs_from_glob(path_glob: Generator[Path, None, None]) -> set[str]:
"""Simply strip the extension from all found files."""
return {file.stem for file in path_glob}

Expand Down Expand Up @@ -48,7 +48,7 @@ def find_valid_verbs(root: Path) -> set[str]:

# Setup environment variables
env = os.environ.copy()
env['TMPDIR'] = tmp_dir
env['TMPDIR'] = str(tmp_dir)
env['WINETRICKS_LATEST_VERSION_CHECK'] = 'disabled'

# Execute winetricks, suppress output
Expand Down
34 changes: 17 additions & 17 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import os
import sys
from .logger import log

from .logger import log, LogLevel


class Engine:
"""Game engines"""

def __init__(self) -> None: # noqa: D107
self.engine_name = None
def __init__(self) -> None:
"""Trys to figure out which engine is used in the current game"""
self.engine_name = ''
self.supported = {
'Dunia 2': 'https://pcgamingwiki.com/wiki/Engine:Dunia_2',
'Unity': 'https://pcgamingwiki.com/wiki/Engine:Unity',
Expand All @@ -33,7 +35,7 @@ def __init__(self) -> None: # noqa: D107
else:
log.info('Engine: unknown Game engine')

if self.engine_name is not None:
if self.engine_name:
log.info('Engine: ' + self.engine_name)
log.info('Engine: ' + self.supported[self.engine_name])

Expand Down Expand Up @@ -88,20 +90,18 @@ def _is_ue4(self) -> bool:
"""Detect Unreal Engine 4"""
return False

def _log(self, ctx: str, msg: str, warn: bool = False) -> None:
def _log(self, ctx: str, msg: str, level: LogLevel = LogLevel.INFO) -> None:
"""Log wrapper"""
if self.engine_name is None:
log.warn(ctx + ': Engine not defined')
return

log_func = log.warn if warn else log.info
log_func(f'{self.engine_name}: {ctx}: {msg}')
log.log(f'{self.engine_name}: {ctx}: {msg}', level)

def name(self) -> str:
"""Report Engine name"""
return self.engine_name

def set(self, _engine: str = None) -> bool:
def set(self, _engine: str) -> bool:
"""Force engine"""
if _engine in self.supported:
self.engine_name = _engine
Expand All @@ -117,7 +117,7 @@ def nosplash(self) -> bool:
self._add_argument('-nosplash')
self._log('nosplash', 'splash screen disabled')
else:
self._log('nosplash', 'not supported', True)
self._log('nosplash', 'not supported', LogLevel.WARN)
return False
return True

Expand All @@ -127,7 +127,7 @@ def info(self) -> bool:
self._add_argument('-help')
self._log('info', 'command line arguments')
else:
self._log('info', 'not supported', True)
self._log('info', 'not supported', LogLevel.WARN)
return False
return True

Expand All @@ -140,7 +140,7 @@ def nointro(self) -> bool:
self._add_argument('-skipintro')
self._log('nointro', 'intro videos disabled')
else:
self._log('nointro', 'not supported', True)
self._log('nointro', 'not supported', LogLevel.WARN)
return False
return True

Expand All @@ -150,7 +150,7 @@ def launcher(self) -> bool:
self._add_argument('-show-screen-selector')
self._log('launcher', 'forced')
else:
self._log('launcher', 'not supported', True)
self._log('launcher', 'not supported', LogLevel.WARN)
return False
return True

Expand All @@ -163,14 +163,14 @@ def windowed(self) -> bool:
self._add_argument('-windowed')
self._log('windowed', 'window')
else:
self._log('windowed', 'not supported', True)
self._log('windowed', 'not supported', LogLevel.WARN)
return False
return True

def resolution(self, res: str = None) -> bool:
def resolution(self, res: str) -> bool:
"""Force screen resolution"""
if not isinstance(res, str):
self._log('resolution', 'not provided')
self._log('resolution', 'not provided', LogLevel.WARN)
return False

res_wh = res.split('x')
Expand All @@ -184,7 +184,7 @@ def resolution(self, res: str = None) -> bool:
self._add_argument('-width ' + res_wh[0] + ' -height ' + res_wh[1])
self._log('resolution', res)
else:
self._log('resolution', 'not supported', True)
self._log('resolution', 'not supported', LogLevel.WARN)
return False
return True

Expand Down
7 changes: 4 additions & 3 deletions fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import csv
from functools import lru_cache
from importlib import import_module
from typing import Optional

try:
from . import config
Expand Down Expand Up @@ -35,7 +36,7 @@ def get_game_id() -> str:
return re.findall(r'\d+', os.environ['STEAM_COMPAT_DATA_PATH'])[-1]

log.crit('Game ID not found in environment variables')
return None
exit()


@lru_cache
Expand Down Expand Up @@ -91,7 +92,7 @@ def get_game_name() -> str:
return 'UNKNOWN'


def get_store_name(store: str) -> str:
def get_store_name(store: str) -> Optional[str]:
"""Mapping for store identifier to store name"""
return {
'amazon': 'Amazon',
Expand All @@ -113,7 +114,7 @@ def get_module_name(game_id: str, default: bool = False, local: bool = False) ->
if game_id.isnumeric():
store = 'steam'
elif os.environ.get('STORE'):
store = os.environ.get('STORE').lower()
store = os.environ.get('STORE', '').lower()

if store != 'steam':
log.info(f'Non-steam game {get_game_name()} ({game_id})')
Expand Down
9 changes: 5 additions & 4 deletions gamefixes-gog/umu-1141086411.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


def main() -> None:
util.winedll_override('d3d8', 'n,b') # GOG's dxcfg / Steam006 fixes
util.winedll_override(
'dsound', 'n,b'
) # Ultimate ASI Loader / Silent Hill 4 Randomizer
# GOG's dxcfg / Steam006 fixes
util.winedll_override('d3d8', util.DllOverride.NATIVE_BUILTIN)

# Ultimate ASI Loader / Silent Hill 4 Randomizer
util.winedll_override('dsound', util.DllOverride.NATIVE_BUILTIN)
4 changes: 2 additions & 2 deletions gamefixes-gog/umu-1580232252.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@


def main() -> None:
util.winedll_override('ddraw', 'n,b')
util.winedll_override('dinput', 'n,b')
util.winedll_override('ddraw', util.DllOverride.NATIVE_BUILTIN)
util.winedll_override('dinput', util.DllOverride.NATIVE_BUILTIN)
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-1584652180.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@


def main() -> None:
util.winedll_override('ddraw', 'n,b') # GOG's dxcfg
util.winedll_override('ddraw', util.DllOverride.NATIVE_BUILTIN) # GOG's dxcfg
4 changes: 2 additions & 2 deletions gamefixes-gog/umu-1771973390.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

def main() -> None:
"""Override for wrapper shipped with the game"""
util.winedll_override('ddraw', 'n,b')
util.winedll_override('dinput', 'n,b')
util.winedll_override('ddraw', util.DllOverride.NATIVE_BUILTIN)
util.winedll_override('dinput', util.DllOverride.NATIVE_BUILTIN)
2 changes: 1 addition & 1 deletion gamefixes-steam/105000.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@


def main() -> None:
util.winedll_override('xaudio2_7', 'd')
util.winedll_override('xaudio2_7', util.DllOverride.DISABLED)
2 changes: 1 addition & 1 deletion gamefixes-steam/1062040.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
def main() -> None:
"""Dragon Star Varnir fix"""
# Fixes the startup process.
util.winedll_override('xactengine3_7', 'n')
util.winedll_override('xactengine3_7', util.DllOverride.NATIVE)
2 changes: 1 addition & 1 deletion gamefixes-steam/1286880.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def main() -> None:
"""Needs builtin vulkan-1"""
util.winedll_override('vulkan-1', 'b')
util.winedll_override('vulkan-1', util.DllOverride.BUILTIN)
4 changes: 2 additions & 2 deletions gamefixes-steam/1500540.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@


def main() -> None:
util.winedll_override('dinput', 'n,b') # DxWrapper component
util.winedll_override('winmm', 'n,b') # Music playback
util.winedll_override('dinput', util.DllOverride.NATIVE_BUILTIN) # DxWrapper component
util.winedll_override('winmm', util.DllOverride.NATIVE_BUILTIN) # Music playback
2 changes: 1 addition & 1 deletion gamefixes-steam/1664350.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def main() -> None:
"""Needs builtin vulkan-1"""
util.winedll_override('vulkan-1', 'b')
util.winedll_override('vulkan-1', util.DllOverride.BUILTIN)
2 changes: 1 addition & 1 deletion gamefixes-steam/1681970.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

def main() -> None:
util.protontricks('klite')
util.winedll_override('winegstreamer', '')
util.winedll_override('winegstreamer', util.DllOverride.DISABLED)
# it uses quartz instead of mfplat on win7
util.protontricks('win7')
2 changes: 1 addition & 1 deletion gamefixes-steam/200490.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@


def main() -> None:
util.winedll_override('libvkd3d-1', 'n')
util.winedll_override('libvkd3d-1', util.DllOverride.NATIVE)
util.protontricks('wmp11')
2 changes: 1 addition & 1 deletion gamefixes-steam/201480.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def main() -> None:
util.protontricks('dsound')
util.protontricks('dswave')
util.protontricks('directplay')
util.winedll_override('streamci', 'n')
util.winedll_override('streamci', util.DllOverride.NATIVE)
5 changes: 2 additions & 3 deletions gamefixes-steam/206480.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Game fix Dungeons & Dragons Online"""

#
from protonfixes import util


def main() -> None:
"""Disable libglesv2"""
# gpu acelleration on wibed3d https://bugs.winehq.org/show_bug.cgi?id=44985
# gpu acceleration on wined3d https://bugs.winehq.org/show_bug.cgi?id=44985
# Make the store work.
util.winedll_override('libglesv2', 'd')
util.winedll_override('libglesv2', util.DllOverride.DISABLED)
2 changes: 1 addition & 1 deletion gamefixes-steam/212500.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def main() -> None:
"""Disable libglesv2"""
## gpu acelleration on wined3d https://bugs.winehq.org/show_bug.cgi?id=44985
# Make the store work.
util.winedll_override('libglesv2', 'd')
util.winedll_override('libglesv2', util.DllOverride.DISABLED)
2 changes: 1 addition & 1 deletion gamefixes-steam/223750.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def main() -> None:
util.protontricks('d3dx11_43')
util.protontricks('d3dcompiler_43')
util.protontricks('d3dcompiler_47')
util.winedll_override('wbemprox', 'n') # doesn't seem to be strictly needed
util.winedll_override('wbemprox', util.DllOverride.NATIVE) # doesn't seem to be strictly needed
2 changes: 1 addition & 1 deletion gamefixes-steam/230820.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@


def main() -> None:
util.winedll_override('xaudio2_7', 'd')
util.winedll_override('xaudio2_7', util.DllOverride.DISABLED)
3 changes: 2 additions & 1 deletion gamefixes-steam/23460.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

def main() -> None:
util.protontricks('dotnet35sp1')
util.winedll_override('libvkd3d-1', util.DllOverride.NATIVE)

# Videos play and audio works but screen is black.
# util.protontricks('quartz')
# util.protontricks('klite')
if os.path.isdir('./data/shared/videos'):
subprocess.call(['mv', './data/shared/videos', './data/shared/_videos'])
util.winedll_override('libvkd3d-1', 'n')
2 changes: 1 addition & 1 deletion gamefixes-steam/237890.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def main() -> None:
util.protontricks('wmp9')
util.winedll_override('winegstreamer', '')
util.winedll_override('winegstreamer', util.DllOverride.DISABLED)
2 changes: 1 addition & 1 deletion gamefixes-steam/243200.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@


def main() -> None:
util.winedll_override('xaudio2_7', 'd')
util.winedll_override('xaudio2_7', util.DllOverride.DISABLED)
2 changes: 1 addition & 1 deletion gamefixes-steam/244210.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def main() -> None:
# Fixes Content Manager (black windows)
util.protontricks('d3dx11_43')
util.protontricks('d3dcompiler_47')
util.winedll_override('dwrite', 'n,b')
util.winedll_override('dwrite', util.DllOverride.NATIVE_BUILTIN)
util.protontricks('win10')
util.set_environment('PULSE_LATENCY_MSEC', '60')
2 changes: 1 addition & 1 deletion gamefixes-steam/244850.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def main() -> None:
<gcServer enabled = "true" />
"""

util.set_xml_options(base_attibutte, game_opts, 'SpaceEngineers.exe.config', 'game')
util.set_xml_options(base_attibutte, game_opts, 'SpaceEngineers.exe.config')

util.append_argument('-skipintro')
4 changes: 2 additions & 2 deletions gamefixes-steam/287310.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
def main() -> None:
"""Sets the necessary dll overrides for the wrappers that are shipped with the game"""
# Set overrides
util.winedll_override('ddraw', 'n')
util.winedll_override('dinput', 'n')
util.winedll_override('ddraw', util.DllOverride.NATIVE)
util.winedll_override('dinput', util.DllOverride.NATIVE)
9 changes: 5 additions & 4 deletions gamefixes-steam/292410.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


def main() -> None:
util.protontricks('lavfilters') # fix videos
util.winedll_override(
'd3d9', 'n,b'
) # in case user uses the ThirteenAG widescreen fix
# fix videos
util.protontricks('lavfilters')

# in case user uses the ThirteenAG widescreen fix
util.winedll_override('d3d9', util.DllOverride.NATIVE_BUILTIN)
2 changes: 1 addition & 1 deletion gamefixes-steam/33990.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@


def main() -> None:
util.winedll_override('libvkd3d-1', 'n')
util.winedll_override('libvkd3d-1', util.DllOverride.NATIVE)
util.protontricks('wmp11')
3 changes: 1 addition & 2 deletions gamefixes-steam/39500.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Game fix for Gothic 3"""

import os
from protonfixes import util


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

util.set_ini_options(game_opts, os.path.join('Ini', 'ge3.ini'), 'cp1251', 'game')
util.set_ini_options(game_opts, 'Ini/ge3.ini', 'cp1251')
4 changes: 2 additions & 2 deletions gamefixes-steam/559620.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

def main() -> None:
# Override ddraw (cutscenes+menu perf) and WinMM (Music)
util.winedll_override('ddraw', 'n,b')
util.winedll_override('winmm', 'n,b')
util.winedll_override('ddraw', util.DllOverride.NATIVE_BUILTIN)
util.winedll_override('winmm', util.DllOverride.NATIVE_BUILTIN)
2 changes: 1 addition & 1 deletion gamefixes-steam/593600.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def main() -> None:
"""Overrides the mprapi.dll to native."""
util.winedll_override('mprapi', 'x')
util.winedll_override('mprapi', util.DllOverride.NATIVE)
2 changes: 1 addition & 1 deletion gamefixes-steam/63710.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def main() -> None:
"""From: https://www.protondb.com/app/63710"""
util.protontricks('d3dcompiler_43')
util.protontricks('d3dx9_43')
util.winedll_override('openal32', 'b')
util.winedll_override('openal32', util.DllOverride.BUILTIN)
Loading
Loading