From b0a8ff7ec9e5148c9bc36819c62f70a6ad85736f Mon Sep 17 00:00:00 2001 From: dyceron Date: Fri, 26 Jul 2024 14:16:01 -0400 Subject: [PATCH 1/7] Add option to adjust volume of music tracks --- .../specific_patches/cosmetic_patches.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py index d15fa89..d6f6010 100644 --- a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py +++ b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py @@ -7,6 +7,7 @@ def patch_cosmetics(editor: PatcherEditor, configuration: dict) -> None: tunables = editor.get_file("system/tunables/tunables.bmtun", Bmtun) tunable_cosmetics(tunables, configuration) music_shuffle(editor, configuration) + volume_patches(editor, configuration) def tunable_cosmetics(tunables: Bmtun, configuration: dict) -> None: @@ -48,3 +49,14 @@ def music_shuffle(editor: PatcherEditor, configuration: dict) -> None: original_track = f"sounds/streams/music/{original}.bcwav" new_track = temp_dict[f"sounds/streams/music/{new}.bcwav"] editor.replace_asset(original_track, new_track) + + +def volume_patches(editor: PatcherEditor, configuratiin: dict) -> None: + sounds = editor.get_file("system/snd/scenariomusicdefs.bmdefs") + properties = sounds.raw["sounds"] + for sound in sounds: + # Apply the configuration value to the track volume + properties["volume"] *= configuration["cosmetic_patches"]["custom_volume"] + # Prevent track volume from being greater than 1.0 + if properties["volume"] > 1.0: + properties["volume"] = 1.0 From bf06b67c6775559c0ef95f23bb8191caa2ddb52e Mon Sep 17 00:00:00 2001 From: dyceron <38679103+dyceron@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:19:28 -0400 Subject: [PATCH 2/7] Update cosmetic_patches.py --- .../specific_patches/cosmetic_patches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py index d6f6010..318ef77 100644 --- a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py +++ b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py @@ -51,7 +51,7 @@ def music_shuffle(editor: PatcherEditor, configuration: dict) -> None: editor.replace_asset(original_track, new_track) -def volume_patches(editor: PatcherEditor, configuratiin: dict) -> None: +def volume_patches(editor: PatcherEditor, configuration: dict) -> None: sounds = editor.get_file("system/snd/scenariomusicdefs.bmdefs") properties = sounds.raw["sounds"] for sound in sounds: From 9ec79cd3a300da71af459921e4c72d65989194db Mon Sep 17 00:00:00 2001 From: dyceron Date: Fri, 26 Jul 2024 15:08:03 -0400 Subject: [PATCH 3/7] Add typing --- .../specific_patches/cosmetic_patches.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py index 318ef77..cd423a4 100644 --- a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py +++ b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py @@ -1,4 +1,4 @@ -from mercury_engine_data_structures.formats.bmtun import Bmtun +from mercury_engine_data_structures.formats import Bmdefs, Bmtun from open_samus_returns_rando.misc_patches import lua_util from open_samus_returns_rando.patcher_editor import PatcherEditor @@ -52,7 +52,7 @@ def music_shuffle(editor: PatcherEditor, configuration: dict) -> None: def volume_patches(editor: PatcherEditor, configuration: dict) -> None: - sounds = editor.get_file("system/snd/scenariomusicdefs.bmdefs") + sounds = editor.get_file("system/snd/scenariomusicdefs.bmdefs", Bmdefs) properties = sounds.raw["sounds"] for sound in sounds: # Apply the configuration value to the track volume From eb84f3ad9dc018a7ff0ac91a87490dc495ca37ba Mon Sep 17 00:00:00 2001 From: dyceron Date: Fri, 26 Jul 2024 17:55:20 -0400 Subject: [PATCH 4/7] Add schema and add config for environment sfx --- .../files/schema.json | 18 +++++++++ .../specific_patches/cosmetic_patches.py | 40 +++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/open_samus_returns_rando/files/schema.json b/src/open_samus_returns_rando/files/schema.json index 8cc002e..caf5b6a 100644 --- a/src/open_samus_returns_rando/files/schema.json +++ b/src/open_samus_returns_rando/files/schema.json @@ -523,6 +523,24 @@ } }, "default": {} + }, + "volume_adjustments": { + "description": "Applies a multiplier to all music tracks to adjust their volumes.", + "type": "object", + "properties": { + "music": { + "minimum": 0, + "maximum": 1 + }, + "environment_sfx": { + "minimum": 0, + "maximum": 1 + } + }, + "default": { + "music": 1, + "environment_sfx": 1 + } } }, "default": {} diff --git a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py index cd423a4..a31e324 100644 --- a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py +++ b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py @@ -1,4 +1,5 @@ -from mercury_engine_data_structures.formats import Bmdefs, Bmtun +from mercury_engine_data_structures.formats import Bmdefs, Bmses, Bmtun +from open_samus_returns_rando.constants import ALL_SCENARIOS from open_samus_returns_rando.misc_patches import lua_util from open_samus_returns_rando.patcher_editor import PatcherEditor @@ -52,11 +53,34 @@ def music_shuffle(editor: PatcherEditor, configuration: dict) -> None: def volume_patches(editor: PatcherEditor, configuration: dict) -> None: - sounds = editor.get_file("system/snd/scenariomusicdefs.bmdefs", Bmdefs) - properties = sounds.raw["sounds"] + music = configuration["volume_adjustments"]["music"] + environment_sfx = configuration["volume_adjustments"]["environment_sfx"] + # If there are no custom values, quit + if music == 1 and environment_sfx == 1: + return + + # Music Adjustments + sound_defs = editor.get_file("system/snd/scenariomusicdefs.bmdefs", Bmdefs) + sounds = sound_defs.raw["sounds"] for sound in sounds: - # Apply the configuration value to the track volume - properties["volume"] *= configuration["cosmetic_patches"]["custom_volume"] - # Prevent track volume from being greater than 1.0 - if properties["volume"] > 1.0: - properties["volume"] = 1.0 + # Apply the music values to each track's music volume + sound["volume"] *= music + + enemies_list = sound_defs.raw["enemies_list"] + for enemy in enemies_list: + areas = enemy["areas"] + for area in areas: + layers = area["layers"] + for layer in layers: + states = layer["states"] + for state in states: + properties = state["properties"] + properties["volume"] *= music + + # Environmetal Sound Adjustments + for scenario in ALL_SCENARIOS: + scenario_file = editor.get_file(f"maps/levels/c10_samus/{scenario}/{scenario}.bmses", Bmses) + env_sounds = scenario_file.raw["sounds"] + for env_sound in env_sounds: + # Apply the enviroment_sfx values to each track's enviroment_sfx volume + env_sound["properties"]["volume"] *= environment_sfx From 5611fb7483f60efbcfa6019005f72934a4d1bdb0 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sat, 27 Jul 2024 09:34:06 -0400 Subject: [PATCH 5/7] Cleanup --- .../specific_patches/cosmetic_patches.py | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py index a31e324..5657308 100644 --- a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py +++ b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py @@ -55,32 +55,27 @@ def music_shuffle(editor: PatcherEditor, configuration: dict) -> None: def volume_patches(editor: PatcherEditor, configuration: dict) -> None: music = configuration["volume_adjustments"]["music"] environment_sfx = configuration["volume_adjustments"]["environment_sfx"] - # If there are no custom values, quit - if music == 1 and environment_sfx == 1: - return # Music Adjustments - sound_defs = editor.get_file("system/snd/scenariomusicdefs.bmdefs", Bmdefs) - sounds = sound_defs.raw["sounds"] - for sound in sounds: - # Apply the music values to each track's music volume - sound["volume"] *= music - - enemies_list = sound_defs.raw["enemies_list"] - for enemy in enemies_list: - areas = enemy["areas"] - for area in areas: - layers = area["layers"] - for layer in layers: - states = layer["states"] - for state in states: - properties = state["properties"] - properties["volume"] *= music - - # Environmetal Sound Adjustments - for scenario in ALL_SCENARIOS: - scenario_file = editor.get_file(f"maps/levels/c10_samus/{scenario}/{scenario}.bmses", Bmses) - env_sounds = scenario_file.raw["sounds"] - for env_sound in env_sounds: - # Apply the enviroment_sfx values to each track's enviroment_sfx volume - env_sound["properties"]["volume"] *= environment_sfx + if music != 1: + sound_defs = editor.get_file("system/snd/scenariomusicdefs.bmdefs", Bmdefs) + sounds = sound_defs.raw["sounds"] + for sound in sounds: + # Apply the music values to each track's music volume + sound["volume"] *= music + + enemies_list = sound_defs.raw["enemies_list"] + for enemy in enemies_list: + for area in enemy["areas"]: + for layer in area["layers"]: + for state in layer["states"]: + state["properties"]["volume"] *= music + + # Environment Sound Adjustments + if environmwnt_sfx != 1: + for scenario in ALL_SCENARIOS: + scenario_file = editor.get_file(f"maps/levels/c10_samus/{scenario}/{scenario}.bmses", Bmses) + env_sounds = scenario_file.raw["sounds"] + for env_sound in env_sounds: + # Apply the enviroment_sfx values to each track's enviroment_sfx volume + env_sound["properties"]["volume"] *= environment_sfx From 16ea004110ed45596349e028c245935f5346b603 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sat, 27 Jul 2024 10:18:25 -0400 Subject: [PATCH 6/7] Fixes --- src/open_samus_returns_rando/files/schema.json | 2 ++ .../specific_patches/cosmetic_patches.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/open_samus_returns_rando/files/schema.json b/src/open_samus_returns_rando/files/schema.json index caf5b6a..8457f5f 100644 --- a/src/open_samus_returns_rando/files/schema.json +++ b/src/open_samus_returns_rando/files/schema.json @@ -529,10 +529,12 @@ "type": "object", "properties": { "music": { + "type": "number", "minimum": 0, "maximum": 1 }, "environment_sfx": { + "type": "number", "minimum": 0, "maximum": 1 } diff --git a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py index 5657308..2525c3a 100644 --- a/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py +++ b/src/open_samus_returns_rando/specific_patches/cosmetic_patches.py @@ -72,7 +72,7 @@ def volume_patches(editor: PatcherEditor, configuration: dict) -> None: state["properties"]["volume"] *= music # Environment Sound Adjustments - if environmwnt_sfx != 1: + if environment_sfx != 1: for scenario in ALL_SCENARIOS: scenario_file = editor.get_file(f"maps/levels/c10_samus/{scenario}/{scenario}.bmses", Bmses) env_sounds = scenario_file.raw["sounds"] From 5bf76a228dc16f3c661f5e412041a55491e59054 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sun, 28 Jul 2024 08:36:24 -0400 Subject: [PATCH 7/7] Schema formatting --- src/open_samus_returns_rando/files/schema.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/open_samus_returns_rando/files/schema.json b/src/open_samus_returns_rando/files/schema.json index 8457f5f..e5cc605 100644 --- a/src/open_samus_returns_rando/files/schema.json +++ b/src/open_samus_returns_rando/files/schema.json @@ -529,12 +529,12 @@ "type": "object", "properties": { "music": { - "type": "number", + "type": "number", "minimum": 0, "maximum": 1 }, "environment_sfx": { - "type": "number", + "type": "number", "minimum": 0, "maximum": 1 }