From d414934e6ab1ec1f4e18e863be003c60c8497319 Mon Sep 17 00:00:00 2001 From: Fabian Arndt Date: Sat, 19 Oct 2024 04:11:30 +0200 Subject: [PATCH] Changed LiteralTypes to Enum classes - Logger: use Enum values for colors - Use default parameters, if argument is equal --- config_base.py | 12 +- engine.py | 18 +-- gamefixes-gog/umu-1141086411.py | 9 +- gamefixes-gog/umu-1580232252.py | 4 +- gamefixes-gog/umu-1584652180.py | 2 +- gamefixes-gog/umu-1771973390.py | 4 +- gamefixes-steam/105000.py | 2 +- gamefixes-steam/1062040.py | 2 +- gamefixes-steam/1286880.py | 2 +- gamefixes-steam/1500540.py | 4 +- gamefixes-steam/1664350.py | 2 +- gamefixes-steam/1681970.py | 2 +- gamefixes-steam/200490.py | 2 +- gamefixes-steam/201480.py | 2 +- gamefixes-steam/206480.py | 2 +- gamefixes-steam/212500.py | 2 +- gamefixes-steam/223750.py | 2 +- gamefixes-steam/230820.py | 2 +- gamefixes-steam/23460.py | 2 +- gamefixes-steam/237890.py | 2 +- gamefixes-steam/243200.py | 2 +- gamefixes-steam/244210.py | 2 +- gamefixes-steam/244850.py | 2 +- gamefixes-steam/2475980.py | 4 +- gamefixes-steam/287310.py | 4 +- gamefixes-steam/292410.py | 9 +- gamefixes-steam/33990.py | 2 +- gamefixes-steam/39500.py | 2 +- gamefixes-steam/559620.py | 4 +- gamefixes-steam/593600.py | 2 +- gamefixes-steam/63710.py | 2 +- gamefixes-steam/65540.py | 8 +- gamefixes-steam/70400.py | 2 +- gamefixes-steam/70420.py | 2 +- gamefixes-steam/950670.py | 2 +- gamefixes-steam/968370.py | 2 +- gamefixes-umu/umu-silenthill3.py | 2 +- gamefixes-umu/umu-starcitizen.py | 2 +- gamefixes-zoomplatform/umu-240200.py | 2 +- ...mu-4bff76f4-566a-4714-b481-95d3343afe22.py | 6 +- logger.py | 40 +++---- util.py | 108 ++++++++++++++---- 42 files changed, 174 insertions(+), 116 deletions(-) diff --git a/config_base.py b/config_base.py index 64774eb2..2263d4a0 100644 --- a/config_base.py +++ b/config_base.py @@ -9,7 +9,7 @@ from typing import Any from collections.abc import Callable -from logger import log, LogLevelType +from logger import log, LogLevel class ConfigBase: """Base class for configuration objects. @@ -35,7 +35,7 @@ def snake_case(cls, input: str) -> str: @staticmethod - def __log(message: str, level: LogLevelType = 'INFO') -> None: + def __log(message: str, level: LogLevel = LogLevel.INFO) -> None: log.log(f'[CONFIG]: {message}', level) @@ -131,7 +131,7 @@ def _get_parse_function(type_name: str) -> Callable[[str], Any]: }.get(type_name, None) if not value: value = parser_items.get - self.__log(f'Unknown type "{type_name}", falling back to "str".', 'WARN') + self.__log(f'Unknown type "{type_name}", falling back to "str".', LogLevel.WARN) return value # Iterate over the option objects in this section @@ -142,7 +142,7 @@ def _get_parse_function(type_name: str) -> Callable[[str], Any]: value = func(option_name) setattr(section, option_name, value) except Exception as ex: - self.__log(f'Failed to parse config file "{file}". Exception: "{ex}"', 'CRIT') + self.__log(f'Failed to parse config file "{file}". Exception: "{ex}"', LogLevel.CRIT) return False return True @@ -158,7 +158,7 @@ def write_config_file(self, file: Path) -> bool: """ # Only precede if the parent directory exists if not file.parent.is_dir(): - self.__log(f'Parent directory "{file.parent}" does not exist. Abort.', 'WARN') + self.__log(f'Parent directory "{file.parent}" does not exist. Abort.', LogLevel.WARN) return False # Create and populate ConfigParser @@ -176,6 +176,6 @@ def write_config_file(self, file: Path) -> bool: with file.open(mode='w') as stream: parser.write(stream) except Exception as ex: - self.__log(f'Failed to create config file "{file}". Exception: "{ex}"', 'CRIT') + self.__log(f'Failed to create config file "{file}". Exception: "{ex}"', LogLevel.CRIT) return False return True diff --git a/engine.py b/engine.py index a3850874..ae0fbc1a 100644 --- a/engine.py +++ b/engine.py @@ -2,7 +2,7 @@ import os import sys -from .logger import log, LogLevelType +from .logger import log, LogLevel class Engine: @@ -89,7 +89,7 @@ def _is_ue4(self) -> bool: """Detect Unreal Engine 4""" return False - def _log(self, ctx: str, msg: str, level: LogLevelType = 'INFO') -> 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') @@ -116,7 +116,7 @@ def nosplash(self) -> bool: self._add_argument('-nosplash') self._log('nosplash', 'splash screen disabled') else: - self._log('nosplash', 'not supported', 'WARN') + self._log('nosplash', 'not supported', LogLevel.WARN) return False return True @@ -126,7 +126,7 @@ def info(self) -> bool: self._add_argument('-help') self._log('info', 'command line arguments') else: - self._log('info', 'not supported', 'WARN') + self._log('info', 'not supported', LogLevel.WARN) return False return True @@ -139,7 +139,7 @@ def nointro(self) -> bool: self._add_argument('-skipintro') self._log('nointro', 'intro videos disabled') else: - self._log('nointro', 'not supported', 'WARN') + self._log('nointro', 'not supported', LogLevel.WARN) return False return True @@ -149,7 +149,7 @@ def launcher(self) -> bool: self._add_argument('-show-screen-selector') self._log('launcher', 'forced') else: - self._log('launcher', 'not supported', 'WARN') + self._log('launcher', 'not supported', LogLevel.WARN) return False return True @@ -162,14 +162,14 @@ def windowed(self) -> bool: self._add_argument('-windowed') self._log('windowed', 'window') else: - self._log('windowed', 'not supported', 'WARN') + self._log('windowed', 'not supported', LogLevel.WARN) return False return True def resolution(self, res: str) -> bool: """Force screen resolution""" if not isinstance(res, str): - self._log('resolution', 'not provided', 'WARN') + self._log('resolution', 'not provided', LogLevel.WARN) return False res_wh = res.split('x') @@ -183,7 +183,7 @@ def resolution(self, res: str) -> bool: self._add_argument('-width ' + res_wh[0] + ' -height ' + res_wh[1]) self._log('resolution', res) else: - self._log('resolution', 'not supported', 'WARN') + self._log('resolution', 'not supported', LogLevel.WARN) return False return True diff --git a/gamefixes-gog/umu-1141086411.py b/gamefixes-gog/umu-1141086411.py index b166d65a..a8099a7d 100644 --- a/gamefixes-gog/umu-1141086411.py +++ b/gamefixes-gog/umu-1141086411.py @@ -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) diff --git a/gamefixes-gog/umu-1580232252.py b/gamefixes-gog/umu-1580232252.py index 26a842e4..51830f7f 100644 --- a/gamefixes-gog/umu-1580232252.py +++ b/gamefixes-gog/umu-1580232252.py @@ -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) diff --git a/gamefixes-gog/umu-1584652180.py b/gamefixes-gog/umu-1584652180.py index fc731bac..5ca937b4 100644 --- a/gamefixes-gog/umu-1584652180.py +++ b/gamefixes-gog/umu-1584652180.py @@ -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 diff --git a/gamefixes-gog/umu-1771973390.py b/gamefixes-gog/umu-1771973390.py index 4ac9a621..0be404a5 100644 --- a/gamefixes-gog/umu-1771973390.py +++ b/gamefixes-gog/umu-1771973390.py @@ -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) diff --git a/gamefixes-steam/105000.py b/gamefixes-steam/105000.py index c4a3d341..246c934c 100755 --- a/gamefixes-steam/105000.py +++ b/gamefixes-steam/105000.py @@ -7,4 +7,4 @@ def main() -> None: - util.winedll_override('xaudio2_7', '') + util.winedll_override('xaudio2_7', util.DllOverride.DISABLED) diff --git a/gamefixes-steam/1062040.py b/gamefixes-steam/1062040.py index b3607c66..e5b70cdb 100755 --- a/gamefixes-steam/1062040.py +++ b/gamefixes-steam/1062040.py @@ -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) diff --git a/gamefixes-steam/1286880.py b/gamefixes-steam/1286880.py index 6238cb3f..6cb8cb34 100755 --- a/gamefixes-steam/1286880.py +++ b/gamefixes-steam/1286880.py @@ -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) diff --git a/gamefixes-steam/1500540.py b/gamefixes-steam/1500540.py index 3ede4b23..a6f98a73 100644 --- a/gamefixes-steam/1500540.py +++ b/gamefixes-steam/1500540.py @@ -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 diff --git a/gamefixes-steam/1664350.py b/gamefixes-steam/1664350.py index 8b466387..298544c4 100755 --- a/gamefixes-steam/1664350.py +++ b/gamefixes-steam/1664350.py @@ -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) diff --git a/gamefixes-steam/1681970.py b/gamefixes-steam/1681970.py index f8c1724c..91c922eb 100755 --- a/gamefixes-steam/1681970.py +++ b/gamefixes-steam/1681970.py @@ -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') diff --git a/gamefixes-steam/200490.py b/gamefixes-steam/200490.py index 22b69394..703fea6c 100755 --- a/gamefixes-steam/200490.py +++ b/gamefixes-steam/200490.py @@ -7,5 +7,5 @@ def main() -> None: - util.winedll_override('libvkd3d-1', 'n') + util.winedll_override('libvkd3d-1', util.DllOverride.NATIVE) util.protontricks('wmp11') diff --git a/gamefixes-steam/201480.py b/gamefixes-steam/201480.py index 0376bf8f..c11eda01 100755 --- a/gamefixes-steam/201480.py +++ b/gamefixes-steam/201480.py @@ -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) diff --git a/gamefixes-steam/206480.py b/gamefixes-steam/206480.py index 1539e29c..b63e41dd 100755 --- a/gamefixes-steam/206480.py +++ b/gamefixes-steam/206480.py @@ -7,4 +7,4 @@ def main() -> None: """Disable libglesv2""" # gpu acceleration on wined3d https://bugs.winehq.org/show_bug.cgi?id=44985 # Make the store work. - util.winedll_override('libglesv2', '') + util.winedll_override('libglesv2', util.DllOverride.DISABLED) diff --git a/gamefixes-steam/212500.py b/gamefixes-steam/212500.py index a226ee3c..fa1a2a5a 100755 --- a/gamefixes-steam/212500.py +++ b/gamefixes-steam/212500.py @@ -7,4 +7,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', '') + util.winedll_override('libglesv2', util.DllOverride.DISABLED) diff --git a/gamefixes-steam/223750.py b/gamefixes-steam/223750.py index b9f894c5..ef351cab 100755 --- a/gamefixes-steam/223750.py +++ b/gamefixes-steam/223750.py @@ -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 diff --git a/gamefixes-steam/230820.py b/gamefixes-steam/230820.py index 4eb03d32..7d3364f0 100755 --- a/gamefixes-steam/230820.py +++ b/gamefixes-steam/230820.py @@ -7,4 +7,4 @@ def main() -> None: - util.winedll_override('xaudio2_7', '') + util.winedll_override('xaudio2_7', util.DllOverride.DISABLED) diff --git a/gamefixes-steam/23460.py b/gamefixes-steam/23460.py index c3310cd7..ca1fa182 100644 --- a/gamefixes-steam/23460.py +++ b/gamefixes-steam/23460.py @@ -9,7 +9,7 @@ def main() -> None: util.protontricks('dotnet35sp1') - util.winedll_override('libvkd3d-1', 'n') + util.winedll_override('libvkd3d-1', util.DllOverride.NATIVE) # Videos play and audio works but screen is black. # util.protontricks('quartz') diff --git a/gamefixes-steam/237890.py b/gamefixes-steam/237890.py index ccd42e24..60c7a4e8 100755 --- a/gamefixes-steam/237890.py +++ b/gamefixes-steam/237890.py @@ -5,4 +5,4 @@ def main() -> None: util.protontricks('wmp9') - util.winedll_override('winegstreamer', '') + util.winedll_override('winegstreamer', util.DllOverride.DISABLED) diff --git a/gamefixes-steam/243200.py b/gamefixes-steam/243200.py index c9d0940a..a2b8e5ae 100755 --- a/gamefixes-steam/243200.py +++ b/gamefixes-steam/243200.py @@ -7,4 +7,4 @@ def main() -> None: - util.winedll_override('xaudio2_7', '') + util.winedll_override('xaudio2_7', util.DllOverride.DISABLED) diff --git a/gamefixes-steam/244210.py b/gamefixes-steam/244210.py index 9d4034a0..e288857b 100755 --- a/gamefixes-steam/244210.py +++ b/gamefixes-steam/244210.py @@ -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') diff --git a/gamefixes-steam/244850.py b/gamefixes-steam/244850.py index 768b1480..d016f925 100755 --- a/gamefixes-steam/244850.py +++ b/gamefixes-steam/244850.py @@ -11,6 +11,6 @@ def main() -> None: """ - 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') diff --git a/gamefixes-steam/2475980.py b/gamefixes-steam/2475980.py index bb46523b..ebb0750d 100644 --- a/gamefixes-steam/2475980.py +++ b/gamefixes-steam/2475980.py @@ -21,9 +21,9 @@ def main_with_id(game_id: str) -> None: # Demo if game_id == '2505910': - util.set_ini_options(cfg_str, 'acsetup.cfg', 'utf-8', 'game')# + util.set_ini_options(cfg_str, 'acsetup.cfg') return # Full for i in range(1, 5): - util.set_ini_options(cfg_str, f'Gobliiins5-Part{i}/acsetup.cfg', 'utf-8', 'game') + util.set_ini_options(cfg_str, f'Gobliiins5-Part{i}/acsetup.cfg') diff --git a/gamefixes-steam/287310.py b/gamefixes-steam/287310.py index 03c3e995..fae3a08b 100755 --- a/gamefixes-steam/287310.py +++ b/gamefixes-steam/287310.py @@ -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) diff --git a/gamefixes-steam/292410.py b/gamefixes-steam/292410.py index e5d70ea2..4eec166f 100644 --- a/gamefixes-steam/292410.py +++ b/gamefixes-steam/292410.py @@ -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) diff --git a/gamefixes-steam/33990.py b/gamefixes-steam/33990.py index 3bf9d5bd..a0f8d448 100755 --- a/gamefixes-steam/33990.py +++ b/gamefixes-steam/33990.py @@ -7,5 +7,5 @@ def main() -> None: - util.winedll_override('libvkd3d-1', 'n') + util.winedll_override('libvkd3d-1', util.DllOverride.NATIVE) util.protontricks('wmp11') diff --git a/gamefixes-steam/39500.py b/gamefixes-steam/39500.py index 75f95012..cb01cc9b 100755 --- a/gamefixes-steam/39500.py +++ b/gamefixes-steam/39500.py @@ -11,4 +11,4 @@ def main() -> None: FpS.Max=0 """ - util.set_ini_options(game_opts, 'Ini/ge3.ini', 'cp1251', 'game') + util.set_ini_options(game_opts, 'Ini/ge3.ini', 'cp1251') diff --git a/gamefixes-steam/559620.py b/gamefixes-steam/559620.py index 8add8978..f6eb8b72 100755 --- a/gamefixes-steam/559620.py +++ b/gamefixes-steam/559620.py @@ -5,5 +5,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) diff --git a/gamefixes-steam/593600.py b/gamefixes-steam/593600.py index 7ba0d38d..31111498 100755 --- a/gamefixes-steam/593600.py +++ b/gamefixes-steam/593600.py @@ -5,4 +5,4 @@ def main() -> None: """Overrides the mprapi.dll to native.""" - util.winedll_override('mprapi', 'n') + util.winedll_override('mprapi', util.DllOverride.NATIVE) diff --git a/gamefixes-steam/63710.py b/gamefixes-steam/63710.py index 466c884d..a0ed4129 100755 --- a/gamefixes-steam/63710.py +++ b/gamefixes-steam/63710.py @@ -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) diff --git a/gamefixes-steam/65540.py b/gamefixes-steam/65540.py index b324c103..2462c2be 100755 --- a/gamefixes-steam/65540.py +++ b/gamefixes-steam/65540.py @@ -11,7 +11,7 @@ def main() -> None: # Fix background music / Gothic 2 startup util.protontricks('directmusic') - util.winedll_override('*dsound', 'b') # Override registry entry + util.winedll_override('*dsound', util.DllOverride.BUILTIN) # Override registry entry # Fix crackling audio util.set_environment('PULSE_LATENCY_MSEC', '90') @@ -21,12 +21,12 @@ def main() -> None: # Gothic 2: https://steamcommunity.com/sharedfiles/filedetails/?id=2787015529 # # This might also be necessary for the GOG release - util.winedll_override('ddraw', 'n,b') + util.winedll_override('ddraw', util.DllOverride.NATIVE_BUILTIN) # Fix extreme mouse stutter and allow additional use of 'GRawInput (mouse fix)' from workshop # Gothic 1: https://steamcommunity.com/sharedfiles/filedetails/?id=3054112346 # Gothic 2: https://steamcommunity.com/sharedfiles/filedetails/?id=3054078559 - util.winedll_override('dinput', 'n,b') + util.winedll_override('dinput', util.DllOverride.NATIVE_BUILTIN) def set_resolution() -> None: @@ -51,4 +51,4 @@ def set_resolution() -> None: """ ) - util.set_ini_options(game_opts, 'system/Gothic.ini', 'cp1251', 'game') + util.set_ini_options(game_opts, 'system/Gothic.ini', 'cp1251') diff --git a/gamefixes-steam/70400.py b/gamefixes-steam/70400.py index dba5f4a9..bc4fafa2 100755 --- a/gamefixes-steam/70400.py +++ b/gamefixes-steam/70400.py @@ -11,7 +11,7 @@ def main() -> None: util.protontricks('dmusic') util.protontricks('dsound') util.protontricks('dswave') - util.winedll_override('streamci', 'n') + util.winedll_override('streamci', util.DllOverride.NATIVE) util.protontricks('sound=alsa') """ Fix for audio stutter/desync diff --git a/gamefixes-steam/70420.py b/gamefixes-steam/70420.py index 3fe708ad..ae5ebaf9 100755 --- a/gamefixes-steam/70420.py +++ b/gamefixes-steam/70420.py @@ -11,7 +11,7 @@ def main() -> None: util.protontricks('dmusic') util.protontricks('dsound') util.protontricks('dswave') - util.winedll_override('streamci', 'n') + util.winedll_override('streamci', util.DllOverride.NATIVE) util.protontricks('sound=alsa') """ Fix for audio stutter/desync diff --git a/gamefixes-steam/950670.py b/gamefixes-steam/950670.py index aedb11ef..9ef4ca35 100644 --- a/gamefixes-steam/950670.py +++ b/gamefixes-steam/950670.py @@ -39,7 +39,7 @@ def modify_settings() -> None: r.DepthOfFieldQuality=0 r.LensFlareQuality=0 """ - util.set_ini_options(game_opts, path, 'utf-8', 'game') + util.set_ini_options(game_opts, path) def clear_logs() -> None: diff --git a/gamefixes-steam/968370.py b/gamefixes-steam/968370.py index cce242d3..3644fca0 100755 --- a/gamefixes-steam/968370.py +++ b/gamefixes-steam/968370.py @@ -6,5 +6,5 @@ def main() -> None: - util.winedll_override('d3d9', '') + util.winedll_override('d3d9', util.DllOverride.DISABLED) util.protontricks('segoe_script') diff --git a/gamefixes-umu/umu-silenthill3.py b/gamefixes-umu/umu-silenthill3.py index 9edce6cf..cefed283 100644 --- a/gamefixes-umu/umu-silenthill3.py +++ b/gamefixes-umu/umu-silenthill3.py @@ -7,4 +7,4 @@ def main() -> None: # Needs directmusic for some cutscenes util.protontricks('directmusic') - util.winedll_override("dsound", "builtin") + util.winedll_override('dsound', util.DllOverride.NATIVE_BUILTIN) diff --git a/gamefixes-umu/umu-starcitizen.py b/gamefixes-umu/umu-starcitizen.py index 00867399..7952c5c5 100644 --- a/gamefixes-umu/umu-starcitizen.py +++ b/gamefixes-umu/umu-starcitizen.py @@ -12,4 +12,4 @@ def main() -> None: util.protontricks('powershell') # RSI Launcher animation - util.winedll_override('libglesv2', 'b') + util.winedll_override('libglesv2', util.DllOverride.BUILTIN) diff --git a/gamefixes-zoomplatform/umu-240200.py b/gamefixes-zoomplatform/umu-240200.py index 738e9da3..e4576893 100644 --- a/gamefixes-zoomplatform/umu-240200.py +++ b/gamefixes-zoomplatform/umu-240200.py @@ -4,5 +4,5 @@ def main() -> None: - util.winedll_override('d3d8', 'n,b') + util.winedll_override('d3d8', util.DllOverride.NATIVE_BUILTIN) util.protontricks('vcrun2019') diff --git a/gamefixes-zoomplatform/umu-4bff76f4-566a-4714-b481-95d3343afe22.py b/gamefixes-zoomplatform/umu-4bff76f4-566a-4714-b481-95d3343afe22.py index 3f4e5344..ee716213 100644 --- a/gamefixes-zoomplatform/umu-4bff76f4-566a-4714-b481-95d3343afe22.py +++ b/gamefixes-zoomplatform/umu-4bff76f4-566a-4714-b481-95d3343afe22.py @@ -4,6 +4,6 @@ def main() -> None: - util.winedll_override('d3d8', 'n,b') - util.winedll_override('ddraw', 'b') - util.winedll_override('winmm', 'n,b') + util.winedll_override('d3d8', util.DllOverride.NATIVE_BUILTIN) + util.winedll_override('ddraw', util.DllOverride.BUILTIN) + util.winedll_override('winmm', util.DllOverride.NATIVE_BUILTIN) diff --git a/logger.py b/logger.py index 90c4c1da..dbb76288 100644 --- a/logger.py +++ b/logger.py @@ -3,32 +3,26 @@ import os import sys -from typing import Literal -from functools import lru_cache +from enum import Enum -# TypeAliases -LogLevelType = Literal['INFO', 'WARN', 'CRIT', 'DEBUG'] +# Enums +class LogLevel(Enum): + """Enum and mapping (level -> color) for log levels""" + RESET = '\u001b[0m' + INFO = '\u001b[34m' + WARN = '\u001b[33m' + CRIT = '\u001b[31m' + DEBUG = '\u001b[35m' class Log: """Log to stderr for steam dumps""" pfx = f'ProtonFixes[{os.getpid()}]' - @staticmethod - @lru_cache - def __get_color(level: LogLevelType) -> str: - return { - 'RESET': '\u001b[0m', - 'INFO': '\u001b[34m', - 'WARN': '\u001b[33m', - 'CRIT': '\u001b[31m', - 'DEBUG': '\u001b[35m', - }.get(level, '') - @classmethod - def __colorize(cls, msg: str, level: LogLevelType) -> str: - color = cls.__get_color(level) - reset = cls.__get_color('RESET') + def __colorize(cls, msg: str, level: LogLevel) -> str: + color = level.value + reset = LogLevel.RESET.value return f'{color}{msg}{reset}' @classmethod @@ -37,7 +31,7 @@ def __call__(cls, msg: str) -> None: cls.log(msg) @classmethod - def log(cls, msg: str = '', level: LogLevelType = 'INFO') -> None: + def log(cls, msg: str = '', level: LogLevel = LogLevel.INFO) -> None: """Prints the log message to stdout the same way as Proton""" # To terminal print(cls.__colorize(f'{cls.pfx} {level}: {msg}', level), file=sys.stderr, flush=True) @@ -49,24 +43,24 @@ def log(cls, msg: str = '', level: LogLevelType = 'INFO') -> None: @classmethod def info(cls, msg: str) -> None: """Wrapper for printing info messages""" - cls.log(msg, 'INFO') + cls.log(msg, LogLevel.INFO) @classmethod def warn(cls, msg: str) -> None: """Wrapper for printing warning messages""" - cls.log(msg, 'WARN') + cls.log(msg, LogLevel.WARN) @classmethod def crit(cls, msg: str) -> None: """Wrapper for printing critical messages""" - cls.log(msg, 'CRIT') + cls.log(msg, LogLevel.CRIT) @classmethod def debug(cls, msg: str) -> None: """Wrapper for printing debug messages""" if 'DEBUG' not in os.environ: return - cls.log(msg, 'DEBUG') + cls.log(msg, LogLevel.DEBUG) log = Log() diff --git a/util.py b/util.py index 00c28302..6e3eec0c 100644 --- a/util.py +++ b/util.py @@ -11,11 +11,13 @@ import subprocess import urllib.request import functools + +from enum import Enum from pathlib import Path from dataclasses import dataclass from datetime import datetime, timezone from socket import socket, AF_INET, SOCK_DGRAM -from typing import Literal, Any, Union, Optional +from typing import Any, Union, Optional from collections.abc import Mapping, Callable try: @@ -33,11 +35,69 @@ log.crit('Unable to hook into Proton main script environment') exit() + # TypeAliases StrPath = Union[str, Path] -BasePathType = Literal['user', 'game'] -OverrideTypes = Literal['n', 'b', 'n,b', 'b,n', ''] -DosDeviceTypes = Literal['hd', 'network', 'floppy', 'cdrom'] + + +# Enums +class BasePath(Enum): + """Enum for base paths + + Attributes: + USER: User's "My Documents" folder in the current prefix + GAME: Game's install folder + """ + USER = 'user' + GAME = 'game' + + +class DosDevice(Enum): + """Enum for dos device types (mounted at 'prefix/dosdevices/') + + Attributes: + NETWORK: A network device (UNC) + FLOPPY: A floppy drive + CD_ROM: A CD ROM drive + HD: A hard disk drive + """ + NETWORK = 'network' + FLOPPY = 'floppy' + CD_ROM = 'cdrom' + HD = 'hd' + + +class DllOverride(Enum): + """Enum for Wine dll override order + + Builtin means dlls that are provided by Wine. + Native means dlls that are provided by the user or application. + + https://gitlab.winehq.org/wine/wine/-/wikis/Wine-User%27s-Guide#dll-overrides + + DLLs usually get resolved in the following order: + + 1. The directory the program was started from. + 2. The current directory. + 3. The Windows system directory. + 4. The Windows directory. + 5. The PATH variable directories. + + Attributes: + DISABLED: Disable dll + NATIVE: Load native dll + BUILTIN: Load builtin dll + NATIVE_BUILTIN: Load native dll first, builtin second + BUILTIN_NATIVE: Load builtin dll first, native second + """ + DISABLED = '' + NATIVE = 'n' + BUILTIN = 'b' + NATIVE_BUILTIN = 'n,b' + BUILTIN_NATIVE = 'b,n' + + +# Helper classes @dataclass class ReplaceType: """Used for replacements""" @@ -45,6 +105,7 @@ class ReplaceType: from_value: str to_value: str + class ProtonVersion: """Parses the proton version and build timestamp""" @@ -59,6 +120,7 @@ def __init__(self, version_string: str) -> None: self.version_name: str = parts[1] +# Functions @functools.lru_cache def protondir() -> Path: """Returns the path to proton""" @@ -406,10 +468,10 @@ def get_game_install_path() -> Path: return install_path -def winedll_override(dll: str, dtype: OverrideTypes) -> None: +def winedll_override(dll: str, dtype: DllOverride) -> None: """Add WINE dll override""" - log.info(f'Overriding {dll}.dll = {dtype}') - setting = f'{dll}={dtype}' + log.info(f'Overriding {dll}.dll = {dtype.value}') + setting = f'{dll}={dtype.value}' protonmain.append_to_env_str( protonmain.g_session.env, 'WINEDLLOVERRIDES', setting, ';' ) @@ -511,12 +573,12 @@ def patch_libcuda() -> bool: def disable_nvapi() -> None: """Disable WINE nv* dlls""" log.info('Disabling NvAPI') - winedll_override('nvapi', '') - winedll_override('nvapi64', '') - winedll_override('nvcuda', '') - winedll_override('nvcuvid', '') - winedll_override('nvencodeapi', '') - winedll_override('nvencodeapi64', '') + winedll_override('nvapi', DllOverride.DISABLED) + winedll_override('nvapi64', DllOverride.DISABLED) + winedll_override('nvcuda', DllOverride.DISABLED) + winedll_override('nvcuvid', DllOverride.DISABLED) + winedll_override('nvencodeapi', DllOverride.DISABLED) + winedll_override('nvencodeapi64', DllOverride.DISABLED) def disable_esync() -> None: @@ -627,12 +689,12 @@ def _get_case_insensitive_name(path: Path) -> Path: return resolved -def _get_config_full_path(cfile: StrPath, base_path: BasePathType) -> Optional[Path]: +def _get_config_full_path(cfile: StrPath, base_path: BasePath) -> Optional[Path]: """Find game's config file""" # Start from 'user'/'game' directories or absolute path - if base_path == 'user': + if base_path == BasePath.USER: cfg_path = protonprefix() / 'drive_c/users/steamuser/My Documents' / cfile - elif base_path == 'game': + elif base_path == BasePath.GAME: cfg_path = get_game_install_path() / cfile else: cfg_path = Path(cfile) @@ -657,7 +719,7 @@ def create_backup_config(cfg_path: Path) -> bool: def set_ini_options( - ini_opts: str, cfile: StrPath, encoding: str, base_path: BasePathType = 'user' + ini_opts: str, cfile: StrPath, encoding: str = 'utf-8', base_path: BasePath = BasePath.GAME ) -> bool: """Edit game's INI config file""" cfg_path = _get_config_full_path(cfile, base_path) @@ -684,7 +746,7 @@ def set_ini_options( def set_xml_options( - base_attibutte: str, xml_line: str, cfile: StrPath, base_path: BasePathType = 'user' + base_attibutte: str, xml_line: str, cfile: StrPath, encoding: str = 'utf-8', base_path: BasePath = BasePath.GAME ) -> bool: """Edit game's XML config file""" xml_path = _get_config_full_path(cfile, base_path) @@ -697,7 +759,7 @@ def set_xml_options( # set options i = 0 - contents = xml_path.read_text(encoding='utf-8').splitlines() + contents = xml_path.read_text(encoding).splitlines() for line in contents: i += 1 if base_attibutte not in line: @@ -706,7 +768,7 @@ def set_xml_options( contents.insert(i, xml_line + '\n') data = str.join('\n', contents) - xml_path.write_text(data, encoding='utf-8') + xml_path.write_text(data, encoding) log.info('XML config patch applied') return True @@ -936,12 +998,12 @@ def set_game_drive(enabled: bool) -> None: protonmain.g_session.compat_config.discard("gamedrive") -def create_dos_device(letter: str = 'r', dev_type: DosDeviceTypes = 'cdrom') -> bool: +def create_dos_device(letter: str = 'r', dev_type: DosDevice = DosDevice.CD_ROM) -> bool: """Create a symlink to '/tmp' in the dosdevices folder of the prefix and register it Args: letter (str, optional): Letter that the device gets assigned to, must be len = 1 - dev_type (DosDeviceTypes, optional): The device's type which will be registered to wine + dev_type (DosDevice, optional): The device's type which will be registered to wine Returns: bool: True, if device was created @@ -956,7 +1018,7 @@ def create_dos_device(letter: str = 'r', dev_type: DosDeviceTypes = 'cdrom') -> dosdevice.symlink_to('/tmp', True) # designate device as CD-ROM, requires 64-bit access - regedit_add('HKLM\\Software\\Wine\\Drives', f'{letter}:', 'REG_SZ', dev_type, True) + regedit_add('HKLM\\Software\\Wine\\Drives', f'{letter}:', 'REG_SZ', dev_type.value, True) return True