Skip to content

Commit

Permalink
Changed LiteralTypes to Enum classes
Browse files Browse the repository at this point in the history
- Logger: use Enum values for colors
- Use default parameters, if argument is equal
  • Loading branch information
Root-Core committed Dec 16, 2024
1 parent 5b94830 commit eeecbd5
Show file tree
Hide file tree
Showing 41 changed files with 173 additions and 115 deletions.
12 changes: 6 additions & 6 deletions config_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)


Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
18 changes: 9 additions & 9 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import sys
from .logger import log, LogLevelType
from .logger import log, LogLevel


class Engine:
Expand Down Expand Up @@ -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')
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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')
Expand All @@ -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

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', '')
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)
2 changes: 1 addition & 1 deletion gamefixes-steam/206480.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion gamefixes-steam/212500.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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', '')
util.winedll_override('xaudio2_7', util.DllOverride.DISABLED)
2 changes: 1 addition & 1 deletion gamefixes-steam/23460.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
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', '')
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/2475980.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
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')
2 changes: 1 addition & 1 deletion gamefixes-steam/39500.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 2 additions & 2 deletions gamefixes-steam/559620.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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', 'n')
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)
8 changes: 4 additions & 4 deletions gamefixes-steam/65540.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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:
Expand All @@ -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')
2 changes: 1 addition & 1 deletion gamefixes-steam/70400.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/70420.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit eeecbd5

Please sign in to comment.