Files
dockipelago/worlds/dk64/randomizer/Patching/PhaseRando.py
Jonathan Tinney 7971961166
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
add schedule I, sonic 1/frontiers/heroes, spirit island
2026-04-02 23:46:36 -07:00

44 lines
2.0 KiB
Python

"""Apply K Rool Phase order."""
from randomizer.Enums.Maps import Maps
from randomizer.Patching.Patcher import LocalROM
from randomizer.Patching.Library.Assets import getPointerLocation, TableNames
def randomize_krool(spoiler, ROM_COPY: LocalROM):
"""Apply K Rool Phase order based on krool_order from spoiler."""
varspaceOffset = spoiler.settings.rom_data
# /* 0x058 */ char k_rool_order[5]; // Order of K. Rool phases: [0,1,2,3,4] dictates DK->Diddy->Lanky->Tiny->Chunky. If K. Rool is being shortened to less than 5 phases, put the unused phases as -1
kroolOffset = 0x058
ROM_COPY.seek(varspaceOffset + kroolOffset)
phaseCount = len(spoiler.settings.krool_order)
ROM_COPY.writeBytes(bytearray(spoiler.settings.krool_order))
for i in range(5 - phaseCount):
ROM_COPY.write(255)
firstPhase = spoiler.settings.krool_order[0]
if firstPhase != 0: # If not starting with DK
# Find Isles->DK Phase loading zone in Pointer table 18 and write new destination map
cont_map_lzs_address = getPointerLocation(TableNames.Triggers, Maps.Isles)
ROM_COPY.seek(cont_map_lzs_address)
lz_count = int.from_bytes(ROM_COPY.readBytes(2), "big")
for lz_id in range(lz_count):
start = (lz_id * 0x38) + 2
ROM_COPY.seek(cont_map_lzs_address + start + 0x12)
lz_map = int.from_bytes(ROM_COPY.readBytes(2), "big")
if lz_map == Maps.KroolDonkeyPhase:
ROM_COPY.seek(cont_map_lzs_address + start + 0x12)
ROM_COPY.writeMultipleBytes(firstPhase, 2)
def randomize_helm(spoiler, ROM_COPY: LocalROM):
"""Apply Helm Room order based on helm_order from spoiler."""
varspaceOffset = spoiler.settings.rom_data
helmOffset = 0x190
ROM_COPY.seek(varspaceOffset + helmOffset)
roomCount = len(spoiler.settings.helm_order)
ROM_COPY.writeBytes(bytearray(spoiler.settings.helm_order))
for i in range(5 - roomCount):
ROM_COPY.write(255)