|
15 | 15 | from ph_rando.common import ShufflerAuxData
|
16 | 16 | from ph_rando.patcher._bmgs import BMGS
|
17 | 17 | from ph_rando.patcher._items import ITEMS
|
18 |
| -from ph_rando.shuffler.aux_models import Area, Chest, DigSpot, Event, SalvageTreasure, Shop, Tree |
| 18 | +from ph_rando.shuffler.aux_models import ( |
| 19 | + Area, |
| 20 | + Chest, |
| 21 | + DigSpot, |
| 22 | + Event, |
| 23 | + MinigameRewardChest, |
| 24 | + SalvageTreasure, |
| 25 | + Shop, |
| 26 | + Tree, |
| 27 | +) |
19 | 28 |
|
20 | 29 | logger = logging.getLogger(__name__)
|
21 | 30 |
|
@@ -387,6 +396,48 @@ def _patch_shop_items(areas: list[Area], input_rom: rom.NintendoDSRom) -> None:
|
387 | 396 | input_rom.arm9 = arm9_executable
|
388 | 397 |
|
389 | 398 |
|
| 399 | +def _patch_minigame_items(areas: list[Area], input_rom: rom.NintendoDSRom) -> None: |
| 400 | + logging.info('Patching minigame items...') |
| 401 | + |
| 402 | + items: dict[str, MinigameRewardChest] = { |
| 403 | + '.'.join([area.name, room.name, chest.name]): chest |
| 404 | + for area in areas |
| 405 | + for room in area.rooms |
| 406 | + for chest in room.chests |
| 407 | + if type(chest) is MinigameRewardChest |
| 408 | + } |
| 409 | + |
| 410 | + # Load overlay table |
| 411 | + overlay_table: dict[int, code.Overlay] = input_rom.loadArm9Overlays() |
| 412 | + |
| 413 | + for name, item in items.items(): |
| 414 | + item_id = ITEMS[item.contents.name] |
| 415 | + if item_id == -1: |
| 416 | + logger.warning(f'Skipping {item.name}, item {item.contents.name} ID is unknown.') |
| 417 | + continue |
| 418 | + elif item.overlay == -1: |
| 419 | + logger.warning(f'Skipping {item.name}, overlay is unknown.') |
| 420 | + continue |
| 421 | + |
| 422 | + logger.info(f'Patching check "{name}" with item {item.contents.name}') |
| 423 | + assert isinstance(item, MinigameRewardChest) |
| 424 | + |
| 425 | + # Note, the offset is stored as a string in the aux data so that it can be represented as |
| 426 | + # a hex value for readability. So, we must convert it to an `int` here. |
| 427 | + try: # TODO: remove this try/catch when all offsets are set correctly in aux data |
| 428 | + overlay_offset = int(item.overlay_offset, base=16) |
| 429 | + except ValueError: |
| 430 | + logger.warning(f'Invalid overlay offset "{item.overlay_offset}" for {item.name}.') |
| 431 | + continue |
| 432 | + |
| 433 | + # Set the item id to the new one. |
| 434 | + overlay_table[item.overlay].data[overlay_offset] = item_id |
| 435 | + |
| 436 | + input_rom.files[overlay_table[item.overlay].fileID] = overlay_table[item.overlay].save( |
| 437 | + compress=False |
| 438 | + ) |
| 439 | + |
| 440 | + |
390 | 441 | def _patch_bmg_events(areas: list[Area], input_rom: rom.NintendoDSRom) -> None:
|
391 | 442 | chests = [
|
392 | 443 | chest
|
|
0 commit comments