From c02343e68874efd57c2e312cb6b7e4f02222e43a Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 22 Jul 2025 11:11:44 -0400 Subject: add workaround env vars, rm old tests --- py_modules/lsfg_vk/config_schema.py | 28 ++++++++++++++++++++++++++-- py_modules/lsfg_vk/configuration.py | 19 ++++++++++++++++--- py_modules/lsfg_vk/plugin.py | 9 +++++++-- 3 files changed, 49 insertions(+), 7 deletions(-) (limited to 'py_modules') diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py index c82d1d3..6a68db1 100644 --- a/py_modules/lsfg_vk/config_schema.py +++ b/py_modules/lsfg_vk/config_schema.py @@ -73,6 +73,20 @@ SCRIPT_ONLY_FIELDS = { field_type=ConfigFieldType.BOOLEAN, default=False, description="disable Steam Deck mode (unlocks hidden settings in some games)" + ), + + "mangohud_workaround": ConfigField( + name="mangohud_workaround", + field_type=ConfigFieldType.BOOLEAN, + default=False, + description="Enables a transparent mangohud overlay, sometimes fixes issues with 2X multiplier in game mode" + ), + + "disable_vkbasalt": ConfigField( + name="disable_vkbasalt", + field_type=ConfigFieldType.BOOLEAN, + default=False, + description="Disables vkBasalt layer which can conflict with LSFG (Reshade, some Decky plugins)" ) } @@ -91,6 +105,8 @@ class ConfigurationData(TypedDict): dxvk_frame_rate: int enable_wow64: bool disable_steamdeck_mode: bool + mangohud_workaround: bool + disable_vkbasalt: bool class ConfigurationManager: @@ -335,6 +351,10 @@ class ConfigurationManager: script_values["enable_wow64"] = value == "1" elif key == "SteamDeck": script_values["disable_steamdeck_mode"] = value == "0" + elif key == "MANGOHUD": + script_values["mangohud_workaround"] = value == "1" + elif key == "DISABLE_VKBASALT": + script_values["disable_vkbasalt"] = value == "1" except (ValueError, KeyError, IndexError) as e: # If parsing fails, log the error and return empty dict (will use defaults) @@ -368,7 +388,9 @@ class ConfigurationManager: experimental_present_mode: str = "fifo", dxvk_frame_rate: int = 0, enable_wow64: bool = False, - disable_steamdeck_mode: bool = False) -> ConfigurationData: + disable_steamdeck_mode: bool = False, + mangohud_workaround: bool = False, + disable_vkbasalt: bool = False) -> ConfigurationData: """Create configuration from individual arguments""" return cast(ConfigurationData, { "dll": dll, @@ -379,5 +401,7 @@ class ConfigurationManager: "experimental_present_mode": experimental_present_mode, "dxvk_frame_rate": dxvk_frame_rate, "enable_wow64": enable_wow64, - "disable_steamdeck_mode": disable_steamdeck_mode + "disable_steamdeck_mode": disable_steamdeck_mode, + "mangohud_workaround": mangohud_workaround, + "disable_vkbasalt": disable_vkbasalt }) diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index 47d0ebc..82982e5 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -65,7 +65,9 @@ class ConfigurationService(BaseService): experimental_present_mode: str = "fifo", dxvk_frame_rate: int = 0, enable_wow64: bool = False, - disable_steamdeck_mode: bool = False) -> ConfigurationResponse: + disable_steamdeck_mode: bool = False, + mangohud_workaround: bool = False, + disable_vkbasalt: bool = False) -> ConfigurationResponse: """Update TOML configuration Args: @@ -78,6 +80,8 @@ class ConfigurationService(BaseService): dxvk_frame_rate: Frame rate cap for DirectX games, before frame multiplier (0 = disabled) enable_wow64: Whether to enable PROTON_USE_WOW64=1 for 32-bit games disable_steamdeck_mode: Whether to disable Steam Deck mode + mangohud_workaround: Whether to enable MangoHud workaround with transparent overlay + disable_vkbasalt: Whether to disable vkBasalt layer Returns: ConfigurationResponse with success status @@ -86,7 +90,8 @@ class ConfigurationService(BaseService): # Create configuration from individual arguments config = ConfigurationManager.create_config_from_args( dll, multiplier, flow_scale, performance_mode, hdr_mode, - experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode + experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode, + mangohud_workaround, disable_vkbasalt ) # Generate TOML content using centralized manager @@ -108,7 +113,8 @@ class ConfigurationService(BaseService): f"performance_mode={performance_mode}, hdr_mode={hdr_mode}, " f"experimental_present_mode='{experimental_present_mode}', " f"dxvk_frame_rate={dxvk_frame_rate}, " - f"enable_wow64={enable_wow64}, disable_steamdeck_mode={disable_steamdeck_mode}") + f"enable_wow64={enable_wow64}, disable_steamdeck_mode={disable_steamdeck_mode}, " + f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}") return self._success_response(ConfigurationResponse, "lsfg configuration updated successfully", @@ -214,6 +220,13 @@ class ConfigurationService(BaseService): if config.get("disable_steamdeck_mode", False): lines.append("export SteamDeck=0") + if config.get("mangohud_workaround", False): + lines.append("export MANGOHUD=1") + lines.append("export MANGOHUD_CONFIG=alpha=0.01,background_alpha=0.01") + + if config.get("disable_vkbasalt", False): + lines.append("export DISABLE_VKBASALT=1") + # Add DXVK_FRAME_RATE if dxvk_frame_rate is set dxvk_frame_rate = config.get("dxvk_frame_rate", 0) if dxvk_frame_rate > 0: diff --git a/py_modules/lsfg_vk/plugin.py b/py_modules/lsfg_vk/plugin.py index 425d7e7..7deed71 100644 --- a/py_modules/lsfg_vk/plugin.py +++ b/py_modules/lsfg_vk/plugin.py @@ -189,7 +189,9 @@ class Plugin: experimental_present_mode: str = "fifo", dxvk_frame_rate: int = 0, enable_wow64: bool = False, - disable_steamdeck_mode: bool = False) -> Dict[str, Any]: + disable_steamdeck_mode: bool = False, + mangohud_workaround: bool = False, + disable_vkbasalt: bool = False) -> Dict[str, Any]: """Update lsfg TOML configuration Args: @@ -202,13 +204,16 @@ class Plugin: dxvk_frame_rate: Frame rate cap for DirectX games, before frame multiplier (0 = disabled) enable_wow64: Whether to enable PROTON_USE_WOW64=1 for 32-bit games disable_steamdeck_mode: Whether to disable Steam Deck mode + mangohud_workaround: Whether to enable MangoHud workaround with transparent overlay + disable_vkbasalt: Whether to disable vkBasalt layer Returns: ConfigurationResponse dict with success status """ return self.configuration_service.update_config( dll, multiplier, flow_scale, performance_mode, hdr_mode, - experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode + experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode, + mangohud_workaround, disable_vkbasalt ) async def update_dll_path(self, dll_path: str) -> Dict[str, Any]: -- cgit v1.2.3 From dfe4c033dd1922a63c8393ab467e9aa58fa757e4 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 22 Jul 2025 11:41:49 -0400 Subject: refactor: update configuration handling to use object-based API --- py_modules/lsfg_vk/configuration.py | 2 +- py_modules/lsfg_vk/plugin.py | 40 ++++++++++++++++--------------------- 2 files changed, 18 insertions(+), 24 deletions(-) (limited to 'py_modules') diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index 82982e5..68ff577 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -222,7 +222,7 @@ class ConfigurationService(BaseService): if config.get("mangohud_workaround", False): lines.append("export MANGOHUD=1") - lines.append("export MANGOHUD_CONFIG=alpha=0.01,background_alpha=0.01") + lines.append("export MANGOHUD_CONFIG=alpha=0.001,background_alpha=0.001") if config.get("disable_vkbasalt", False): lines.append("export DISABLE_VKBASALT=1") diff --git a/py_modules/lsfg_vk/plugin.py b/py_modules/lsfg_vk/plugin.py index 7deed71..d126d84 100644 --- a/py_modules/lsfg_vk/plugin.py +++ b/py_modules/lsfg_vk/plugin.py @@ -184,36 +184,30 @@ class Plugin: "defaults": ConfigurationManager.get_defaults() } - async def update_lsfg_config(self, dll: str, multiplier: int, flow_scale: float, - performance_mode: bool, hdr_mode: bool, - experimental_present_mode: str = "fifo", - dxvk_frame_rate: int = 0, - enable_wow64: bool = False, - disable_steamdeck_mode: bool = False, - mangohud_workaround: bool = False, - disable_vkbasalt: bool = False) -> Dict[str, Any]: - """Update lsfg TOML configuration + async def update_lsfg_config(self, config: Dict[str, Any]) -> Dict[str, Any]: + """Update lsfg TOML configuration using object-based API Args: - dll: Path to Lossless.dll - multiplier: LSFG multiplier value - flow_scale: LSFG flow scale value - performance_mode: Whether to enable performance mode - hdr_mode: Whether to enable HDR mode - experimental_present_mode: Experimental Vulkan present mode override - dxvk_frame_rate: Frame rate cap for DirectX games, before frame multiplier (0 = disabled) - enable_wow64: Whether to enable PROTON_USE_WOW64=1 for 32-bit games - disable_steamdeck_mode: Whether to disable Steam Deck mode - mangohud_workaround: Whether to enable MangoHud workaround with transparent overlay - disable_vkbasalt: Whether to disable vkBasalt layer + config: Configuration data dictionary containing all settings Returns: ConfigurationResponse dict with success status """ + # Validate and extract configuration from the config dict + validated_config = ConfigurationManager.validate_config(config) + return self.configuration_service.update_config( - dll, multiplier, flow_scale, performance_mode, hdr_mode, - experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode, - mangohud_workaround, disable_vkbasalt + dll=validated_config["dll"], + multiplier=validated_config["multiplier"], + flow_scale=validated_config["flow_scale"], + performance_mode=validated_config["performance_mode"], + hdr_mode=validated_config["hdr_mode"], + experimental_present_mode=validated_config["experimental_present_mode"], + dxvk_frame_rate=validated_config["dxvk_frame_rate"], + enable_wow64=validated_config["enable_wow64"], + disable_steamdeck_mode=validated_config["disable_steamdeck_mode"], + mangohud_workaround=validated_config["mangohud_workaround"], + disable_vkbasalt=validated_config["disable_vkbasalt"] ) async def update_dll_path(self, dll_path: str) -> Dict[str, Any]: -- cgit v1.2.3 From f8139896f2077a95a78a54c818637f78dd102de8 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 22 Jul 2025 12:11:53 -0400 Subject: consolidate toml and script values --- py_modules/lsfg_vk/config_schema.py | 54 ++++++++++++------------------------ py_modules/lsfg_vk/configuration.py | 55 +++++++++++++++++++++++++++++++++++-- py_modules/lsfg_vk/plugin.py | 17 ++---------- 3 files changed, 73 insertions(+), 53 deletions(-) (limited to 'py_modules') diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py index 6a68db1..eac5a91 100644 --- a/py_modules/lsfg_vk/config_schema.py +++ b/py_modules/lsfg_vk/config_schema.py @@ -52,42 +52,16 @@ CONFIG_SCHEMA["dll"] = ConfigField( description="specify where Lossless.dll is stored" ) -# Fields that should ONLY be in the lsfg script, not in TOML config +# Get script-only fields dynamically from shared config SCRIPT_ONLY_FIELDS = { - "dxvk_frame_rate": ConfigField( - name="dxvk_frame_rate", - field_type=ConfigFieldType.INTEGER, - default=0, - description="base framerate cap for DirectX games, before frame multiplier (0 = disabled, requires game re-launch)" - ), - - "enable_wow64": ConfigField( - name="enable_wow64", - field_type=ConfigFieldType.BOOLEAN, - default=False, - description="enable PROTON_USE_WOW64=1 for 32-bit games (use with ProtonGE to fix crashing)" - ), - - "disable_steamdeck_mode": ConfigField( - name="disable_steamdeck_mode", - field_type=ConfigFieldType.BOOLEAN, - default=False, - description="disable Steam Deck mode (unlocks hidden settings in some games)" - ), - - "mangohud_workaround": ConfigField( - name="mangohud_workaround", - field_type=ConfigFieldType.BOOLEAN, - default=False, - description="Enables a transparent mangohud overlay, sometimes fixes issues with 2X multiplier in game mode" - ), - - "disable_vkbasalt": ConfigField( - name="disable_vkbasalt", - field_type=ConfigFieldType.BOOLEAN, - default=False, - description="Disables vkBasalt layer which can conflict with LSFG (Reshade, some Decky plugins)" + field_name: ConfigField( + name=field_def["name"], + field_type=ConfigFieldType(field_def["fieldType"]), + default=field_def["default"], + description=field_def["description"] ) + for field_name, field_def in CONFIG_SCHEMA_DEF.items() + if field_def.get("location") == "script" } # Complete configuration schema (TOML + script-only fields) @@ -107,6 +81,8 @@ class ConfigurationData(TypedDict): disable_steamdeck_mode: bool mangohud_workaround: bool disable_vkbasalt: bool + foobar_toggle: bool + test_config_only: str class ConfigurationManager: @@ -355,6 +331,8 @@ class ConfigurationManager: script_values["mangohud_workaround"] = value == "1" elif key == "DISABLE_VKBASALT": script_values["disable_vkbasalt"] = value == "1" + elif key == "FOOBAR": + script_values["foobar_toggle"] = value == "1" except (ValueError, KeyError, IndexError) as e: # If parsing fails, log the error and return empty dict (will use defaults) @@ -390,7 +368,9 @@ class ConfigurationManager: enable_wow64: bool = False, disable_steamdeck_mode: bool = False, mangohud_workaround: bool = False, - disable_vkbasalt: bool = False) -> ConfigurationData: + disable_vkbasalt: bool = False, + foobar_toggle: bool = False, + test_config_only: str = "default_value") -> ConfigurationData: """Create configuration from individual arguments""" return cast(ConfigurationData, { "dll": dll, @@ -403,5 +383,7 @@ class ConfigurationManager: "enable_wow64": enable_wow64, "disable_steamdeck_mode": disable_steamdeck_mode, "mangohud_workaround": mangohud_workaround, - "disable_vkbasalt": disable_vkbasalt + "disable_vkbasalt": disable_vkbasalt, + "foobar_toggle": foobar_toggle, + "test_config_only": test_config_only }) diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index 68ff577..b4c7994 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -60,6 +60,47 @@ class ConfigurationService(BaseService): f"Using default configuration due to parse error: {str(e)}", config=config) + def update_config_from_dict(self, config: ConfigurationData) -> ConfigurationResponse: + """Update TOML configuration from configuration dictionary (eliminates parameter duplication) + + Args: + config: Complete configuration data dictionary + + Returns: + ConfigurationResponse with success status + """ + try: + # Generate TOML content using centralized manager + toml_content = ConfigurationManager.generate_toml_content(config) + + # Ensure config directory exists + self.config_dir.mkdir(parents=True, exist_ok=True) + + # Write the updated config directly to preserve inode for file watchers + self._write_file(self.config_file_path, toml_content, 0o644) + + # Update the launch script with the new configuration + script_result = self.update_lsfg_script(config) + if not script_result["success"]: + self.log.warning(f"Failed to update launch script: {script_result['error']}") + + # Log with dynamic field listing + field_values = ", ".join(f"{k}={repr(v)}" for k, v in config.items()) + self.log.info(f"Updated lsfg configuration: {field_values}") + + return self._success_response(ConfigurationResponse, + "lsfg configuration updated successfully", + config=config) + + except (OSError, IOError) as e: + error_msg = f"Error updating lsfg config: {str(e)}" + self.log.error(error_msg) + return self._error_response(ConfigurationResponse, str(e), config=None) + except ValueError as e: + error_msg = f"Invalid configuration arguments: {str(e)}" + self.log.error(error_msg) + return self._error_response(ConfigurationResponse, str(e), config=None) + def update_config(self, dll: str, multiplier: int, flow_scale: float, performance_mode: bool, hdr_mode: bool, experimental_present_mode: str = "fifo", @@ -67,7 +108,9 @@ class ConfigurationService(BaseService): enable_wow64: bool = False, disable_steamdeck_mode: bool = False, mangohud_workaround: bool = False, - disable_vkbasalt: bool = False) -> ConfigurationResponse: + disable_vkbasalt: bool = False, + foobar_toggle: bool = False, + test_config_only: str = "default_value") -> ConfigurationResponse: """Update TOML configuration Args: @@ -82,6 +125,8 @@ class ConfigurationService(BaseService): disable_steamdeck_mode: Whether to disable Steam Deck mode mangohud_workaround: Whether to enable MangoHud workaround with transparent overlay disable_vkbasalt: Whether to disable vkBasalt layer + foobar_toggle: Test script-only toggle that exports FOOBAR=1 + test_config_only: Test TOML-only configuration field Returns: ConfigurationResponse with success status @@ -91,7 +136,7 @@ class ConfigurationService(BaseService): config = ConfigurationManager.create_config_from_args( dll, multiplier, flow_scale, performance_mode, hdr_mode, experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode, - mangohud_workaround, disable_vkbasalt + mangohud_workaround, disable_vkbasalt, foobar_toggle, test_config_only ) # Generate TOML content using centralized manager @@ -114,7 +159,8 @@ class ConfigurationService(BaseService): f"experimental_present_mode='{experimental_present_mode}', " f"dxvk_frame_rate={dxvk_frame_rate}, " f"enable_wow64={enable_wow64}, disable_steamdeck_mode={disable_steamdeck_mode}, " - f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}") + f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}, " + f"foobar_toggle={foobar_toggle}, test_config_only='{test_config_only}'") return self._success_response(ConfigurationResponse, "lsfg configuration updated successfully", @@ -227,6 +273,9 @@ class ConfigurationService(BaseService): if config.get("disable_vkbasalt", False): lines.append("export DISABLE_VKBASALT=1") + if config.get("foobar_toggle", False): + lines.append("export FOOBAR=1") + # Add DXVK_FRAME_RATE if dxvk_frame_rate is set dxvk_frame_rate = config.get("dxvk_frame_rate", 0) if dxvk_frame_rate > 0: diff --git a/py_modules/lsfg_vk/plugin.py b/py_modules/lsfg_vk/plugin.py index d126d84..8fa2435 100644 --- a/py_modules/lsfg_vk/plugin.py +++ b/py_modules/lsfg_vk/plugin.py @@ -185,7 +185,7 @@ class Plugin: } async def update_lsfg_config(self, config: Dict[str, Any]) -> Dict[str, Any]: - """Update lsfg TOML configuration using object-based API + """Update lsfg TOML configuration using object-based API (single source of truth) Args: config: Configuration data dictionary containing all settings @@ -196,19 +196,8 @@ class Plugin: # Validate and extract configuration from the config dict validated_config = ConfigurationManager.validate_config(config) - return self.configuration_service.update_config( - dll=validated_config["dll"], - multiplier=validated_config["multiplier"], - flow_scale=validated_config["flow_scale"], - performance_mode=validated_config["performance_mode"], - hdr_mode=validated_config["hdr_mode"], - experimental_present_mode=validated_config["experimental_present_mode"], - dxvk_frame_rate=validated_config["dxvk_frame_rate"], - enable_wow64=validated_config["enable_wow64"], - disable_steamdeck_mode=validated_config["disable_steamdeck_mode"], - mangohud_workaround=validated_config["mangohud_workaround"], - disable_vkbasalt=validated_config["disable_vkbasalt"] - ) + # Use dynamic parameter passing based on schema + return self.configuration_service.update_config_from_dict(validated_config) async def update_dll_path(self, dll_path: str) -> Dict[str, Any]: """Update the DLL path in the configuration when detected -- cgit v1.2.3 From f8c09209513507ad9af7822c32119cf6d6fae0ac Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 22 Jul 2025 12:40:23 -0400 Subject: rm test config options --- py_modules/lsfg_vk/config_schema.py | 12 ++---------- py_modules/lsfg_vk/configuration.py | 14 +++----------- 2 files changed, 5 insertions(+), 21 deletions(-) (limited to 'py_modules') diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py index eac5a91..6728106 100644 --- a/py_modules/lsfg_vk/config_schema.py +++ b/py_modules/lsfg_vk/config_schema.py @@ -81,8 +81,6 @@ class ConfigurationData(TypedDict): disable_steamdeck_mode: bool mangohud_workaround: bool disable_vkbasalt: bool - foobar_toggle: bool - test_config_only: str class ConfigurationManager: @@ -331,8 +329,6 @@ class ConfigurationManager: script_values["mangohud_workaround"] = value == "1" elif key == "DISABLE_VKBASALT": script_values["disable_vkbasalt"] = value == "1" - elif key == "FOOBAR": - script_values["foobar_toggle"] = value == "1" except (ValueError, KeyError, IndexError) as e: # If parsing fails, log the error and return empty dict (will use defaults) @@ -368,9 +364,7 @@ class ConfigurationManager: enable_wow64: bool = False, disable_steamdeck_mode: bool = False, mangohud_workaround: bool = False, - disable_vkbasalt: bool = False, - foobar_toggle: bool = False, - test_config_only: str = "default_value") -> ConfigurationData: + disable_vkbasalt: bool = False) -> ConfigurationData: """Create configuration from individual arguments""" return cast(ConfigurationData, { "dll": dll, @@ -383,7 +377,5 @@ class ConfigurationManager: "enable_wow64": enable_wow64, "disable_steamdeck_mode": disable_steamdeck_mode, "mangohud_workaround": mangohud_workaround, - "disable_vkbasalt": disable_vkbasalt, - "foobar_toggle": foobar_toggle, - "test_config_only": test_config_only + "disable_vkbasalt": disable_vkbasalt }) diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index b4c7994..49653ea 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -108,9 +108,7 @@ class ConfigurationService(BaseService): enable_wow64: bool = False, disable_steamdeck_mode: bool = False, mangohud_workaround: bool = False, - disable_vkbasalt: bool = False, - foobar_toggle: bool = False, - test_config_only: str = "default_value") -> ConfigurationResponse: + disable_vkbasalt: bool = False) -> ConfigurationResponse: """Update TOML configuration Args: @@ -125,8 +123,6 @@ class ConfigurationService(BaseService): disable_steamdeck_mode: Whether to disable Steam Deck mode mangohud_workaround: Whether to enable MangoHud workaround with transparent overlay disable_vkbasalt: Whether to disable vkBasalt layer - foobar_toggle: Test script-only toggle that exports FOOBAR=1 - test_config_only: Test TOML-only configuration field Returns: ConfigurationResponse with success status @@ -136,7 +132,7 @@ class ConfigurationService(BaseService): config = ConfigurationManager.create_config_from_args( dll, multiplier, flow_scale, performance_mode, hdr_mode, experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode, - mangohud_workaround, disable_vkbasalt, foobar_toggle, test_config_only + mangohud_workaround, disable_vkbasalt ) # Generate TOML content using centralized manager @@ -159,8 +155,7 @@ class ConfigurationService(BaseService): f"experimental_present_mode='{experimental_present_mode}', " f"dxvk_frame_rate={dxvk_frame_rate}, " f"enable_wow64={enable_wow64}, disable_steamdeck_mode={disable_steamdeck_mode}, " - f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}, " - f"foobar_toggle={foobar_toggle}, test_config_only='{test_config_only}'") + f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}") return self._success_response(ConfigurationResponse, "lsfg configuration updated successfully", @@ -273,9 +268,6 @@ class ConfigurationService(BaseService): if config.get("disable_vkbasalt", False): lines.append("export DISABLE_VKBASALT=1") - if config.get("foobar_toggle", False): - lines.append("export FOOBAR=1") - # Add DXVK_FRAME_RATE if dxvk_frame_rate is set dxvk_frame_rate = config.get("dxvk_frame_rate", 0) if dxvk_frame_rate > 0: -- cgit v1.2.3 From df0635f1bba611b8b44975057acd579102d209dd Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 22 Jul 2025 13:06:46 -0400 Subject: further automate population of hardcoded fields --- py_modules/lsfg_vk/config_schema.py | 64 ++--------- py_modules/lsfg_vk/config_schema_generated.py | 118 +++++++++++++++++++++ py_modules/lsfg_vk/configuration.py | 44 +++----- .../lsfg_vk/configuration_helpers_generated.py | 22 ++++ 4 files changed, 164 insertions(+), 84 deletions(-) create mode 100644 py_modules/lsfg_vk/config_schema_generated.py create mode 100644 py_modules/lsfg_vk/configuration_helpers_generated.py (limited to 'py_modules') diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py index 6728106..a7827ae 100644 --- a/py_modules/lsfg_vk/config_schema.py +++ b/py_modules/lsfg_vk/config_schema.py @@ -19,6 +19,9 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent)) from shared_config import CONFIG_SCHEMA_DEF, ConfigFieldType, get_field_names, get_defaults, get_field_types +# Import auto-generated configuration components +from .config_schema_generated import ConfigurationData, get_script_parsing_logic, get_script_generation_logic + @dataclass class ConfigField: @@ -68,19 +71,11 @@ SCRIPT_ONLY_FIELDS = { COMPLETE_CONFIG_SCHEMA = {**CONFIG_SCHEMA, **SCRIPT_ONLY_FIELDS} -class ConfigurationData(TypedDict): - """Type-safe configuration data structure""" - dll: str - multiplier: int - flow_scale: float - performance_mode: bool - hdr_mode: bool - experimental_present_mode: str - dxvk_frame_rate: int - enable_wow64: bool - disable_steamdeck_mode: bool - mangohud_workaround: bool - disable_vkbasalt: bool +# Import auto-generated configuration components +from .config_schema_generated import ConfigurationData, get_script_parsing_logic, get_script_generation_logic + +# Note: ConfigurationData is now imported from generated file +# No need to manually maintain the TypedDict anymore! class ConfigurationManager: @@ -295,46 +290,9 @@ class ConfigurationManager: Returns: Dict containing parsed script-only field values """ - script_values = {} - - try: - lines = script_content.split('\n') - - for line in lines: - line = line.strip() - - # Skip comments, empty lines, and non-export lines - if not line or line.startswith('#') or not line.startswith('export '): - continue - - # Parse export statements: export VAR=value - if '=' in line: - # Remove 'export ' prefix - export_line = line[len('export '):] - key, value = export_line.split('=', 1) - key = key.strip() - value = value.strip() - - # Map environment variables to config field names - if key == "DXVK_FRAME_RATE": - try: - script_values["dxvk_frame_rate"] = int(value) - except ValueError: - pass - elif key == "PROTON_USE_WOW64": - script_values["enable_wow64"] = value == "1" - elif key == "SteamDeck": - script_values["disable_steamdeck_mode"] = value == "0" - elif key == "MANGOHUD": - script_values["mangohud_workaround"] = value == "1" - elif key == "DISABLE_VKBASALT": - script_values["disable_vkbasalt"] = value == "1" - - except (ValueError, KeyError, IndexError) as e: - # If parsing fails, log the error and return empty dict (will use defaults) - print(f"Error parsing script content: {e}") - - return script_values + # Use auto-generated parsing logic + parse_script_values = get_script_parsing_logic() + return parse_script_values(script_content.split('\n')) @staticmethod def merge_config_with_script(toml_config: ConfigurationData, script_values: Dict[str, Union[bool, int, str]]) -> ConfigurationData: diff --git a/py_modules/lsfg_vk/config_schema_generated.py b/py_modules/lsfg_vk/config_schema_generated.py new file mode 100644 index 0000000..46bc58f --- /dev/null +++ b/py_modules/lsfg_vk/config_schema_generated.py @@ -0,0 +1,118 @@ +""" +Auto-generated configuration schema components from shared_config.py +DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build +""" + +from typing import TypedDict, Dict, Any, Union, cast +from enum import Enum +import sys +from pathlib import Path + +# Import shared configuration constants +sys.path.insert(0, str(Path(__file__).parent.parent.parent)) +from shared_config import CONFIG_SCHEMA_DEF, ConfigFieldType + + +class ConfigurationData(TypedDict): + """Type-safe configuration data structure - AUTO-GENERATED""" + dll: str + multiplier: int + flow_scale: float + performance_mode: bool + hdr_mode: bool + experimental_present_mode: str + dxvk_frame_rate: int + enable_wow64: bool + disable_steamdeck_mode: bool + mangohud_workaround: bool + disable_vkbasalt: bool + + +def get_script_parsing_logic(): + """Return the script parsing logic as a callable""" + def parse_script_values(lines): + script_values = {} + for line in lines: + line = line.strip() + if not line or line.startswith("#") or not line.startswith("export "): + continue + if "=" in line: + export_line = line[len("export "):] + key, value = export_line.split("=", 1) + key = key.strip() + value = value.strip() + + # Auto-generated parsing logic: + if key == "DXVK_FRAME_RATE": + try: + script_values["dxvk_frame_rate"] = int(value) + except ValueError: + pass + if key == "PROTON_USE_WOW64": + script_values["enable_wow64"] = value == "1" + if key == "SteamDeck": + script_values["disable_steamdeck_mode"] = value == "0" + if key == "MANGOHUD": + script_values["mangohud_workaround"] = value == "1" + if key == "DISABLE_VKBASALT": + script_values["disable_vkbasalt"] = value == "1" + + return script_values + return parse_script_values + + +def get_script_generation_logic(): + """Return the script generation logic as a callable""" + def generate_script_lines(config): + lines = [] + dxvk_frame_rate = config.get("dxvk_frame_rate", 0) + if dxvk_frame_rate > 0: + lines.append(f"export DXVK_FRAME_RATE={dxvk_frame_rate}") + if config.get("enable_wow64", False): + lines.append("export PROTON_USE_WOW64=1") + if config.get("disable_steamdeck_mode", False): + lines.append("export SteamDeck=0") + if config.get("mangohud_workaround", False): + lines.append("export MANGOHUD=1") + if config.get("disable_vkbasalt", False): + lines.append("export DISABLE_VKBASALT=1") + return lines + return generate_script_lines + + +def get_function_parameters() -> str: + """Return function signature parameters""" + return """dll: str = "/games/Lossless Scaling/Lossless.dll", + multiplier: int = 1, + flow_scale: float = 0.8, + performance_mode: bool = True, + hdr_mode: bool = False, + experimental_present_mode: str = "fifo", + dxvk_frame_rate: int = 0, + enable_wow64: bool = False, + disable_steamdeck_mode: bool = False, + mangohud_workaround: bool = False, + disable_vkbasalt: bool = False""" + + +def create_config_dict(**kwargs) -> ConfigurationData: + """Create configuration dictionary from keyword arguments""" + return cast(ConfigurationData, { + "dll": dll, + "multiplier": multiplier, + "flow_scale": flow_scale, + "performance_mode": performance_mode, + "hdr_mode": hdr_mode, + "experimental_present_mode": experimental_present_mode, + "dxvk_frame_rate": dxvk_frame_rate, + "enable_wow64": enable_wow64, + "disable_steamdeck_mode": disable_steamdeck_mode, + "mangohud_workaround": mangohud_workaround, + "disable_vkbasalt": disable_vkbasalt, + }) + + +# Field lists for dynamic operations +TOML_FIELDS = ['dll', 'multiplier', 'flow_scale', 'performance_mode', 'hdr_mode', 'experimental_present_mode'] +SCRIPT_FIELDS = ['dxvk_frame_rate', 'enable_wow64', 'disable_steamdeck_mode', 'mangohud_workaround', 'disable_vkbasalt'] +ALL_FIELDS = ['dll', 'multiplier', 'flow_scale', 'performance_mode', 'hdr_mode', 'experimental_present_mode', 'dxvk_frame_rate', 'enable_wow64', 'disable_steamdeck_mode', 'mangohud_workaround', 'disable_vkbasalt'] diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index 49653ea..e745e29 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -6,7 +6,9 @@ from pathlib import Path from typing import Dict, Any from .base_service import BaseService -from .config_schema import ConfigurationManager, ConfigurationData, CONFIG_SCHEMA +from .config_schema import ConfigurationManager, CONFIG_SCHEMA +from .config_schema_generated import ConfigurationData, get_script_generation_logic +from .configuration_helpers_generated import log_configuration_update from .types import ConfigurationResponse @@ -149,13 +151,8 @@ class ConfigurationService(BaseService): if not script_result["success"]: self.log.warning(f"Failed to update launch script: {script_result['error']}") - self.log.info(f"Updated lsfg TOML configuration: " - f"dll='{dll}', multiplier={multiplier}, flow_scale={flow_scale}, " - f"performance_mode={performance_mode}, hdr_mode={hdr_mode}, " - f"experimental_present_mode='{experimental_present_mode}', " - f"dxvk_frame_rate={dxvk_frame_rate}, " - f"enable_wow64={enable_wow64}, disable_steamdeck_mode={disable_steamdeck_mode}, " - f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}") + # Use auto-generated logging + log_configuration_update(self.log, config) return self._success_response(ConfigurationResponse, "lsfg configuration updated successfully", @@ -254,29 +251,14 @@ class ConfigurationService(BaseService): "# This script sets up the environment for lsfg-vk to work with the plugin configuration" ] - # Add optional export statements based on configuration - if config.get("enable_wow64", False): - lines.append("export PROTON_USE_WOW64=1") + # Use auto-generated script generation logic + generate_script_lines = get_script_generation_logic() + lines.extend(generate_script_lines(config)) - if config.get("disable_steamdeck_mode", False): - lines.append("export SteamDeck=0") - - if config.get("mangohud_workaround", False): - lines.append("export MANGOHUD=1") - lines.append("export MANGOHUD_CONFIG=alpha=0.001,background_alpha=0.001") - - if config.get("disable_vkbasalt", False): - lines.append("export DISABLE_VKBASALT=1") - - # Add DXVK_FRAME_RATE if dxvk_frame_rate is set - dxvk_frame_rate = config.get("dxvk_frame_rate", 0) - if dxvk_frame_rate > 0: - lines.append(f"export DXVK_FRAME_RATE={dxvk_frame_rate}") - - # Always add the LSFG_PROCESS export - lines.append("export LSFG_PROCESS=decky-lsfg-vk") - - # Add the execution line - lines.append('exec "$@"') + # Always add the LSFG_PROCESS export and execution line + lines.extend([ + "export LSFG_PROCESS=decky-lsfg-vk", + 'exec "$@"' + ]) return "\n".join(lines) + "\n" diff --git a/py_modules/lsfg_vk/configuration_helpers_generated.py b/py_modules/lsfg_vk/configuration_helpers_generated.py new file mode 100644 index 0000000..f9f4a65 --- /dev/null +++ b/py_modules/lsfg_vk/configuration_helpers_generated.py @@ -0,0 +1,22 @@ +""" +Auto-generated configuration helper functions from shared_config.py +DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build +""" + +from typing import Dict, Any +from .config_schema_generated import ConfigurationData, ALL_FIELDS + + +def log_configuration_update(logger, config: ConfigurationData) -> None: + """Log configuration update with all field values""" + logger.info(f"Updated lsfg TOML configuration: dll={config['dll']}, multiplier={config['multiplier']}, flow_scale={config['flow_scale']}, performance_mode={config['performance_mode']}, hdr_mode={config['hdr_mode']}, experimental_present_mode={config['experimental_present_mode']}, dxvk_frame_rate={config['dxvk_frame_rate']}, enable_wow64={config['enable_wow64']}, disable_steamdeck_mode={config['disable_steamdeck_mode']}, mangohud_workaround={config['mangohud_workaround']}, disable_vkbasalt={config['disable_vkbasalt']}") + + +def get_config_field_names() -> list[str]: + """Get all configuration field names""" + return ALL_FIELDS.copy() + + +def extract_config_values(config: ConfigurationData) -> Dict[str, Any]: + """Extract configuration values as a dictionary""" + return {field: config[field] for field in ALL_FIELDS} -- cgit v1.2.3 From d063284dea10e82a23c2c332ecd4901d7254171b Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 22 Jul 2025 13:23:25 -0400 Subject: use generated kwargs and config in more hardcoded places --- py_modules/lsfg_vk/config_schema.py | 36 ++++++++------------------- py_modules/lsfg_vk/config_schema_generated.py | 35 ++++++++++++++++++-------- py_modules/lsfg_vk/configuration.py | 36 ++++++--------------------- py_modules/lsfg_vk/installation.py | 7 +++--- 4 files changed, 47 insertions(+), 67 deletions(-) (limited to 'py_modules') diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py index a7827ae..bbace42 100644 --- a/py_modules/lsfg_vk/config_schema.py +++ b/py_modules/lsfg_vk/config_schema.py @@ -171,7 +171,9 @@ class ConfigurationManager: if config.get("dll"): lines.append("[global]") lines.append(f"# specify where Lossless.dll is stored") - lines.append(f'dll = "{config["dll"]}"') + # Generate TOML lines for TOML fields only - USE GENERATED CONSTANTS + from .config_schema_generated import DLL + lines.append(f'dll = "{config[DLL]}"') lines.append("") # Add game section with process name for LSFG_PROCESS approach @@ -248,9 +250,10 @@ class ConfigurationManager: elif value.startswith("'") and value.endswith("'"): value = value[1:-1] - # Handle global section (dll only) + # Handle global section (dll only) - USE GENERATED CONSTANTS if in_global_section and key == "dll": - config["dll"] = value + from .config_schema_generated import DLL + config[DLL] = value # Handle game section elif in_game_section: @@ -315,25 +318,8 @@ class ConfigurationManager: return cast(ConfigurationData, merged_config) @staticmethod - def create_config_from_args(dll: str, multiplier: int, flow_scale: float, - performance_mode: bool, hdr_mode: bool, - experimental_present_mode: str = "fifo", - dxvk_frame_rate: int = 0, - enable_wow64: bool = False, - disable_steamdeck_mode: bool = False, - mangohud_workaround: bool = False, - disable_vkbasalt: bool = False) -> ConfigurationData: - """Create configuration from individual arguments""" - return cast(ConfigurationData, { - "dll": dll, - "multiplier": multiplier, - "flow_scale": flow_scale, - "performance_mode": performance_mode, - "hdr_mode": hdr_mode, - "experimental_present_mode": experimental_present_mode, - "dxvk_frame_rate": dxvk_frame_rate, - "enable_wow64": enable_wow64, - "disable_steamdeck_mode": disable_steamdeck_mode, - "mangohud_workaround": mangohud_workaround, - "disable_vkbasalt": disable_vkbasalt - }) + @staticmethod + def create_config_from_args(**kwargs) -> ConfigurationData: + """Create configuration from keyword arguments - USES GENERATED CODE""" + from .config_schema_generated import create_config_dict + return create_config_dict(**kwargs) diff --git a/py_modules/lsfg_vk/config_schema_generated.py b/py_modules/lsfg_vk/config_schema_generated.py index 46bc58f..cc90207 100644 --- a/py_modules/lsfg_vk/config_schema_generated.py +++ b/py_modules/lsfg_vk/config_schema_generated.py @@ -12,6 +12,19 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent)) from shared_config import CONFIG_SCHEMA_DEF, ConfigFieldType +# Field name constants for type-safe access +DLL = "dll" +MULTIPLIER = "multiplier" +FLOW_SCALE = "flow_scale" +PERFORMANCE_MODE = "performance_mode" +HDR_MODE = "hdr_mode" +EXPERIMENTAL_PRESENT_MODE = "experimental_present_mode" +DXVK_FRAME_RATE = "dxvk_frame_rate" +ENABLE_WOW64 = "enable_wow64" +DISABLE_STEAMDECK_MODE = "disable_steamdeck_mode" +MANGOHUD_WORKAROUND = "mangohud_workaround" +DISABLE_VKBASALT = "disable_vkbasalt" + class ConfigurationData(TypedDict): """Type-safe configuration data structure - AUTO-GENERATED""" @@ -98,17 +111,17 @@ def get_function_parameters() -> str: def create_config_dict(**kwargs) -> ConfigurationData: """Create configuration dictionary from keyword arguments""" return cast(ConfigurationData, { - "dll": dll, - "multiplier": multiplier, - "flow_scale": flow_scale, - "performance_mode": performance_mode, - "hdr_mode": hdr_mode, - "experimental_present_mode": experimental_present_mode, - "dxvk_frame_rate": dxvk_frame_rate, - "enable_wow64": enable_wow64, - "disable_steamdeck_mode": disable_steamdeck_mode, - "mangohud_workaround": mangohud_workaround, - "disable_vkbasalt": disable_vkbasalt, + "dll": kwargs.get("dll"), + "multiplier": kwargs.get("multiplier"), + "flow_scale": kwargs.get("flow_scale"), + "performance_mode": kwargs.get("performance_mode"), + "hdr_mode": kwargs.get("hdr_mode"), + "experimental_present_mode": kwargs.get("experimental_present_mode"), + "dxvk_frame_rate": kwargs.get("dxvk_frame_rate"), + "enable_wow64": kwargs.get("enable_wow64"), + "disable_steamdeck_mode": kwargs.get("disable_steamdeck_mode"), + "mangohud_workaround": kwargs.get("mangohud_workaround"), + "disable_vkbasalt": kwargs.get("disable_vkbasalt"), }) diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index e745e29..b9ee174 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -103,39 +103,18 @@ class ConfigurationService(BaseService): self.log.error(error_msg) return self._error_response(ConfigurationResponse, str(e), config=None) - def update_config(self, dll: str, multiplier: int, flow_scale: float, - performance_mode: bool, hdr_mode: bool, - experimental_present_mode: str = "fifo", - dxvk_frame_rate: int = 0, - enable_wow64: bool = False, - disable_steamdeck_mode: bool = False, - mangohud_workaround: bool = False, - disable_vkbasalt: bool = False) -> ConfigurationResponse: - """Update TOML configuration + def update_config(self, **kwargs) -> ConfigurationResponse: + """Update TOML configuration using generated schema - SIMPLIFIED WITH GENERATED CODE Args: - dll: Path to Lossless.dll - multiplier: LSFG multiplier value - flow_scale: LSFG flow scale value - performance_mode: Whether to enable performance mode - hdr_mode: Whether to enable HDR mode - experimental_present_mode: Experimental Vulkan present mode override - dxvk_frame_rate: Frame rate cap for DirectX games, before frame multiplier (0 = disabled) - enable_wow64: Whether to enable PROTON_USE_WOW64=1 for 32-bit games - disable_steamdeck_mode: Whether to disable Steam Deck mode - mangohud_workaround: Whether to enable MangoHud workaround with transparent overlay - disable_vkbasalt: Whether to disable vkBasalt layer + **kwargs: Configuration field values (see shared_config.py for available fields) Returns: ConfigurationResponse with success status """ try: - # Create configuration from individual arguments - config = ConfigurationManager.create_config_from_args( - dll, multiplier, flow_scale, performance_mode, hdr_mode, - experimental_present_mode, dxvk_frame_rate, enable_wow64, disable_steamdeck_mode, - mangohud_workaround, disable_vkbasalt - ) + # Create configuration from keyword arguments using generated function + config = ConfigurationManager.create_config_from_args(**kwargs) # Generate TOML content using centralized manager toml_content = ConfigurationManager.generate_toml_content(config) @@ -187,8 +166,9 @@ class ConfigurationService(BaseService): else: config = current_response["config"] - # Update just the DLL path - config["dll"] = dll_path + # Update just the DLL path - USE GENERATED CONSTANTS + from .config_schema_generated import DLL + config[DLL] = dll_path # Generate TOML content and write it toml_content = ConfigurationManager.generate_toml_content(config) diff --git a/py_modules/lsfg_vk/installation.py b/py_modules/lsfg_vk/installation.py index b340093..996a03f 100644 --- a/py_modules/lsfg_vk/installation.py +++ b/py_modules/lsfg_vk/installation.py @@ -121,9 +121,10 @@ class InstallationService(BaseService): self._write_file(self.config_file_path, toml_content, 0o644) self.log.info(f"Created config file at {self.config_file_path}") - # Log detected DLL path if found - if config["dll"]: - self.log.info(f"Configured DLL path: {config['dll']}") + # Log detected DLL path if found - USE GENERATED CONSTANTS + from .config_schema_generated import DLL + if config[DLL]: + self.log.info(f"Configured DLL path: {config[DLL]}") def _create_lsfg_launch_script(self) -> None: """Create the ~/lsfg launch script for easier game setup""" -- cgit v1.2.3