Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize Goron Game + Salvatore Game rewards #199

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion ph_rando/patcher/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
from ph_rando.common import ShufflerAuxData
from ph_rando.patcher._bmgs import BMGS
from ph_rando.patcher._items import ITEMS
from ph_rando.shuffler.aux_models import Area, Chest, DigSpot, Event, SalvageTreasure, Shop, Tree
from ph_rando.shuffler.aux_models import (
Area,
Chest,
DigSpot,
Event,
MinigameRewardChest,
SalvageTreasure,
Shop,
Tree,
)

logger = logging.getLogger(__name__)

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


def _patch_minigame_items(areas: list[Area], input_rom: rom.NintendoDSRom) -> None:
logging.info('Patching minigame items...')

items: dict[str, MinigameRewardChest] = {
'.'.join([area.name, room.name, chest.name]): chest
for area in areas
for room in area.rooms
for chest in room.chests
if type(chest) is MinigameRewardChest
}

# Load overlay table
overlay_table: dict[int, code.Overlay] = input_rom.loadArm9Overlays()

for name, item in items.items():
item_id = ITEMS[item.contents.name]
if item_id == -1:
logger.warning(f'Skipping {item.name}, item {item.contents.name} ID is unknown.')
continue
elif item.overlay == -1:
logger.warning(f'Skipping {item.name}, overlay is unknown.')
continue

logger.info(f'Patching check "{name}" with item {item.contents.name}')
assert isinstance(item, MinigameRewardChest)

# Note, the offset is stored as a string in the aux data so that it can be represented as
# a hex value for readability. So, we must convert it to an `int` here.
try: # TODO: remove this try/catch when all offsets are set correctly in aux data
overlay_offset = int(item.overlay_offset, base=16)
except ValueError:
logger.warning(f'Invalid overlay offset "{item.overlay_offset}" for {item.name}.')
continue

# Set the item id to the new one.
overlay_table[item.overlay].data[overlay_offset] = item_id

input_rom.files[overlay_table[item.overlay].fileID] = overlay_table[item.overlay].save(
compress=False
)


def _patch_bmg_events(areas: list[Area], input_rom: rom.NintendoDSRom) -> None:
chests = [
chest
Expand Down
4 changes: 4 additions & 0 deletions ph_rando/shuffler/aux_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class DigSpot(BaseCheck):

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


Expand Down
15 changes: 14 additions & 1 deletion ph_rando/shuffler/aux_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,25 @@
"const": "minigame_reward_chest",
"title": "Type",
"type": "string"
},
"overlay": {
"description": "The code overlay this minigame chest item is on",
"title": "Overlay",
"type": "integer"
},
"overlay_offset": {
"description": "Hex offset from overlay to the minigame chest item",
"minLength": 1,
"title": "Overlay Offset",
"type": "string"
}
},
"required": [
"name",
"contents",
"type"
"type",
"overlay",
"overlay_offset"
],
"title": "MinigameRewardChest",
"type": "object"
Expand Down
2 changes: 2 additions & 0 deletions ph_rando/shuffler/logic/NW Sea/Bannan Island/Bannan.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"contents": {
"name": "BombBagUpgrade"
},
"overlay": -1,
"overlay_offset": "0",
"display_name": "Win the minigame"
},
{
Expand Down
2 changes: 2 additions & 0 deletions ph_rando/shuffler/logic/SE Sea/Dee Ess Island/DeeEss.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"contents": {
"name": "BombchuBagUpgrade"
},
"overlay": 52,
"overlay_offset": "0xCDC",
"display_name": "Win Gongoron minigame"
},
{
Expand Down
Loading