diff --git a/src/mars_patcher/mf/auto_generated_types.py b/src/mars_patcher/mf/auto_generated_types.py index 523ebd3..dffca76 100644 --- a/src/mars_patcher/mf/auto_generated_types.py +++ b/src/mars_patcher/mf/auto_generated_types.py @@ -513,6 +513,23 @@ class MarsschemamfCreditstextItem(typ.TypedDict, total=False): ] +class MarsschemamfEnvironmentaldamage(typ.TypedDict): + Lava: Typeu8 = 20 + """The amount of damage per second taken while submerged in lava.""" + + Acid: Typeu8 = 60 + """The amount of damage per second taken while submerged in acid.""" + + Heat: Typeu8 = 6 + """The amount of damage per second taken while in a heated environment.""" + + Cold: Typeu8 = 6 + """The amount of damage per second taken while in a cold environment.""" + + Subzero: Typeu8 = 15 + """The amount of damage per second taken while in Sub-Zero Containment. Currently unused, will always use Cold.""" + + @typ.final class MarsschemamfLeveledits(typ.TypedDict, total=False): """Specifies the Room ID.""" @@ -633,6 +650,7 @@ class Marsschemamf(typ.TypedDict, total=False): DisableSoundEffects: bool = False """Disables all sound effects when true.""" + EnvironmentalDamage: MarsschemamfEnvironmentaldamage MissileLimit: Typeu8 = 3 """Changes how many missiles can be on-screen at a time. The vanilla game has it set to 2, the randomizer changes it to 3 by default. Zero Mission uses 4.""" diff --git a/src/mars_patcher/mf/constants/reserved_space.py b/src/mars_patcher/mf/constants/reserved_space.py index 7fe926d..a4fab0a 100644 --- a/src/mars_patcher/mf/constants/reserved_space.py +++ b/src/mars_patcher/mf/constants/reserved_space.py @@ -36,7 +36,7 @@ class ReservedPointersMF(IntEnum): STARTING_LOCATION_ADDR = auto() CREDITS_PARAMETERS_ADDR = auto() # Unused. Remnant of when we didn't have looping credits music HINT_SECURITY_LEVELS_ADDR = auto() - ENVIRONMENTAL_HARZARD_DAMAGE_ADDR = auto() # TODO: Implement this + ENVIRONMENTAL_HAZARD_DAMAGE_ADDR = auto() MISSILE_LIMIT_ADDR = auto() ROOM_NAMES_TABLE_ADDR = auto() REVEAL_HIDDEN_TILES_ADDR = auto() diff --git a/src/mars_patcher/mf/data/schema.json b/src/mars_patcher/mf/data/schema.json index 82d7582..8a27163 100644 --- a/src/mars_patcher/mf/data/schema.json +++ b/src/mars_patcher/mf/data/schema.json @@ -586,6 +586,37 @@ "description": "Disables all sound effects when true.", "default": false }, + "EnvironmentalDamage": { + "type": "object", + "properties": { + "Lava": { + "$ref": "#/$defs/TypeU8", + "description": "The amount of damage per second taken while submerged in lava.", + "default": 20 + }, + "Acid": { + "$ref": "#/$defs/TypeU8", + "description": "The amount of damage per second taken while submerged in acid.", + "default": 60 + }, + "Heat": { + "$ref": "#/$defs/TypeU8", + "description": "The amount of damage per second taken while in a heated environment.", + "default": 6 + }, + "Cold": { + "$ref": "#/$defs/TypeU8", + "description": "The amount of damage per second taken while in a cold environment.", + "default": 6 + }, + "Subzero": { + "$ref": "#/$defs/TypeU8", + "description": "The amount of damage per second taken while in Sub-Zero Containment. Currently unused, will always use Cold.", + "default": 15 + } + }, + "required": ["Lava", "Acid", "Heat", "Cold", "Subzero"] + }, "MissileLimit": { "$ref": "#/$defs/TypeU8", "description": "Changes how many missiles can be on-screen at a time. The vanilla game has it set to 2, the randomizer changes it to 3 by default. Zero Mission uses 4.", diff --git a/src/mars_patcher/mf/misc_patches.py b/src/mars_patcher/mf/misc_patches.py index 5d341cd..0201caf 100644 --- a/src/mars_patcher/mf/misc_patches.py +++ b/src/mars_patcher/mf/misc_patches.py @@ -1,4 +1,5 @@ import mars_patcher.constants.game_data as gd +from mars_patcher.mf.auto_generated_types import MarsschemamfEnvironmentaldamage from mars_patcher.mf.constants.reserved_space import ReservedPointersMF from mars_patcher.mf.data import get_data_path from mars_patcher.patching import BpsDecoder, IpsDecoder @@ -85,6 +86,20 @@ def apply_alternative_health_layout(rom: Rom) -> None: rom.write_8(rom.read_ptr(ReservedPointersMF.USE_ALTERNATIVE_HUD_DISPLAY.value), 1) +def apply_environmental_damage(rom: Rom, damage_dict: MarsschemamfEnvironmentaldamage) -> None: + base_address = rom.read_ptr(ReservedPointersMF.ENVIRONMENTAL_HAZARD_DAMAGE_ADDR.value) + damage = [ + damage_dict["Lava"], + damage_dict["Acid"], + damage_dict["Heat"], + # ASM currently has Subzero and Cold mislabelled. https://github.com/MetroidAdvRandomizerSystem/mars-fusion-asm/issues/374 + damage_dict["Cold"], + damage_dict["Subzero"], + ] + for offset, damage_amount in enumerate(damage): + rom.write_8(base_address + offset, damage_amount) + + def apply_reveal_hidden_tiles(rom: Rom) -> None: rom.write_8(rom.read_ptr(ReservedPointersMF.REVEAL_HIDDEN_TILES_ADDR.value), 1) diff --git a/src/mars_patcher/mf/patcher.py b/src/mars_patcher/mf/patcher.py index 1a4b99e..0c4b674 100644 --- a/src/mars_patcher/mf/patcher.py +++ b/src/mars_patcher/mf/patcher.py @@ -18,6 +18,7 @@ apply_accessibility_patch, apply_alternative_health_layout, apply_base_patch, + apply_environmental_damage, apply_instant_unmorph_patch, apply_nerf_gerons, apply_reveal_hidden_tiles, @@ -151,6 +152,9 @@ def patch_mf( if patch_data.get("DisableSoundEffects"): disable_sound_effects(rom) + if environmental_damage := patch_data.get("EnvironmentalDamage"): + apply_environmental_damage(rom, environmental_damage) + if "MissileLimit" in patch_data: change_missile_limit(rom, patch_data["MissileLimit"])