Skip to content

Commit 360686a

Browse files
authored
Merge pull request #199 from phst-randomizer/randomize-minigame-rewards
Randomize Goron Game + Salvatore Game rewards
2 parents 3204150 + 8694bf4 commit 360686a

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

ph_rando/patcher/_util.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
from ph_rando.common import ShufflerAuxData
1616
from ph_rando.patcher._bmgs import BMGS
1717
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+
)
1928

2029
logger = logging.getLogger(__name__)
2130

@@ -387,6 +396,48 @@ def _patch_shop_items(areas: list[Area], input_rom: rom.NintendoDSRom) -> None:
387396
input_rom.arm9 = arm9_executable
388397

389398

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+
390441
def _patch_bmg_events(areas: list[Area], input_rom: rom.NintendoDSRom) -> None:
391442
chests = [
392443
chest

ph_rando/shuffler/aux_models.py

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ class DigSpot(BaseCheck):
115115

116116
class MinigameRewardChest(BaseCheck):
117117
type: Literal['minigame_reward_chest']
118+
overlay: int = Field(..., description='The code overlay this minigame chest item is on')
119+
overlay_offset: str = Field(
120+
..., description='Hex offset from overlay to the minigame chest item', min_length=1
121+
)
118122
# TODO: what other fields are needed?
119123

120124

ph_rando/shuffler/aux_schema.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,25 @@
362362
"const": "minigame_reward_chest",
363363
"title": "Type",
364364
"type": "string"
365+
},
366+
"overlay": {
367+
"description": "The code overlay this minigame chest item is on",
368+
"title": "Overlay",
369+
"type": "integer"
370+
},
371+
"overlay_offset": {
372+
"description": "Hex offset from overlay to the minigame chest item",
373+
"minLength": 1,
374+
"title": "Overlay Offset",
375+
"type": "string"
365376
}
366377
},
367378
"required": [
368379
"name",
369380
"contents",
370-
"type"
381+
"type",
382+
"overlay",
383+
"overlay_offset"
371384
],
372385
"title": "MinigameRewardChest",
373386
"type": "object"

ph_rando/shuffler/logic/NW Sea/Bannan Island/Bannan.json

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"contents": {
3232
"name": "BombBagUpgrade"
3333
},
34+
"overlay": -1,
35+
"overlay_offset": "0",
3436
"display_name": "Win the minigame"
3537
},
3638
{

ph_rando/shuffler/logic/SE Sea/Dee Ess Island/DeeEss.json

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"contents": {
2222
"name": "BombchuBagUpgrade"
2323
},
24+
"overlay": 52,
25+
"overlay_offset": "0xCDC",
2426
"display_name": "Win Gongoron minigame"
2527
},
2628
{

0 commit comments

Comments
 (0)