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

writeFunction can't be called during cosmetic patching #2136

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
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
165 changes: 8 additions & 157 deletions base-hack/asm/hookcode/boss.asm
Original file line number Diff line number Diff line change
@@ -1,152 +1,3 @@
Jump_KRoolLankyPhaseFix:
j KRoolLankyPhaseFix
nop
Jump_KKOPhaseHandler:
j KKOPhaseHandler
nop
Jump_KKOInitPhase:
j KKOInitPhase
nop
Jump_MadJackShort:
j MadJackShort
nop
Jump_PufftossShort:
j PufftossShort
nop
Jump_DogadonRematchShort:
j DogadonRematchShort
nop
Jump_DilloRematchShort:
j DilloRematchShort
nop
Jump_DKPhaseShort:
j DKPhaseShort
nop
Jump_ChunkyPhaseShort:
j ChunkyPhaseShort
nop
Jump_TinyPhaseShort:
j TinyPhaseShort
nop
Jump_ChunkyPhaseAddedSave:
j ChunkyPhaseAddedSave
nop


PatchKRoolCode:
lui $t3, hi(Jump_KRoolLankyPhaseFix)
lw $t3, lo(Jump_KRoolLankyPhaseFix) ($t3)
lui $t4, 0x8003
sw $t3, 0x8CCC ($t4)
sw $zero, 0x8CD0 ($t4)

lui $t3, hi(KKOPhaseRandoOn)
lbu $t3, lo(KKOPhaseRandoOn) ($t3)
beqz $t3, PatchKRoolCode_0
nop

lui $t3, hi(Jump_KKOPhaseHandler)
lw $t3, lo(Jump_KKOPhaseHandler) ($t3)
lui $t4, 0x8003
sw $t3, 0x2570 ($t4)
sw $zero, 0x2574 ($t4)

lui $t3, hi(Jump_KKOInitPhase)
lw $t3, lo(Jump_KKOInitPhase) ($t3)
lui $t4, 0x8003
sw $t3, 0x1B2C ($t4)
sw $zero, 0x1B30 ($t4)

; KKO Last Phase Check
lui $t3, 0x8003
addiu $t4, $zero, 4
sh $t4, 0x259A ($t3)

; KKO Enemy Check
lui $t3, hi(KKOPhaseOrder + 1)
lbu $t3, lo(KKOPhaseOrder + 1) ($t3)
lui $t4, 0x8003
sh $t3, 0x2566 ($t4)

PatchKRoolCode_0:
lui $t3, hi(ShorterBosses)
lbu $t3, lo(ShorterBosses) ($t3)
beqz $t3, PatchKRoolCode_1
nop

lui $t3, hi(Jump_MadJackShort)
lw $t3, lo(Jump_MadJackShort) ($t3)
lui $t4, 0x8003
sw $t3, 0x5120 ($t4)
sw $zero, 0x5124 ($t4)

; Mad Jack Cutscene Memery
lui $t3, 0x8003
addiu $t4, $zero, 2
sh $t4, 0x50D2 ($t3)

lui $t3, hi(Jump_PufftossShort)
lw $t3, lo(Jump_PufftossShort) ($t3)
lui $t4, 0x8003
sw $t3, 0x9AAC ($t4)
sw $zero, 0x9AB0 ($t4)

lui $t3, hi(Jump_DogadonRematchShort)
lw $t3, lo(Jump_DogadonRematchShort) ($t3)
lui $t4, 0x8003
sw $t3, 0xACB0 ($t4)
sw $zero, 0xACB4 ($t4)

lui $t3, hi(Jump_DilloRematchShort)
lw $t3, lo(Jump_DilloRematchShort) ($t3)
lui $t4, 0x8002
sw $t3, 0x57CC ($t4)
sw $zero, 0x57D0 ($t4)

; KKO Phase Hit Limit
lui $t3, 0x8003
addiu $t4, $zero, 2
sh $t4, 0x22BA ($t3)

lui $t3, hi(Jump_DKPhaseShort)
lw $t3, lo(Jump_DKPhaseShort) ($t3)
lui $t4, 0x8003
sw $t3, 0xDB10 ($t4)
sw $zero, 0xDB14 ($t4)

; Diddy Phase Hit Count
lui $t3, 0x8003
addiu $t4, $zero, 2
sh $t4, 0xE52A ($t3)

; Lanky Phase Hit Count
lui $t3, 0x8003
addiu $t4, $zero, 2
sh $t4, 0xEF02 ($t3)

lui $t3, hi(Jump_TinyPhaseShort)
lw $t3, lo(Jump_TinyPhaseShort) ($t3)
lui $t4, 0x8003
sw $t3, 0x0370 ($t4)
sw $zero, 0x0374 ($t4)

lui $t3, hi(Jump_ChunkyPhaseShort)
lw $t3, lo(Jump_ChunkyPhaseShort) ($t3)
lui $t4, 0x8003
sw $t3, 0x14B4 ($t4)
sw $zero, 0x14B8 ($t4)

PatchKRoolCode_1:
lui $t3, hi(Jump_ChunkyPhaseAddedSave)
lw $t3, lo(Jump_ChunkyPhaseAddedSave) ($t3)
lui $t4, 0x8003
sw $t3, 0x1378 ($t4)
sw $zero, 0x137C ($t4)


jr ra
nop

KRoolLankyPhaseFix:
lui $a1, 0x8003
lbu $a2, 0x43 ($sp)
Expand All @@ -156,23 +7,23 @@ KRoolLankyPhaseFix:
lh $a1, 0x59A0 ($a1)

KKOPhaseHandler:
lui v0, hi(KKOPhaseOrder)
addiu v0, v0, lo(KKOPhaseOrder)
lb $a0, 0x0 (v0)
lui $v0, hi(KKOPhaseOrder)
addiu $v0, $v0, lo(KKOPhaseOrder)
lb $a0, 0x0 ($v0)
bne $t7, $a0, KKOPhaseHandler_Slot2
nop
b KKOPhaseHandler_Finish
lb $t8, 0x1 (v0)
lb $t8, 0x1 ($v0)

KKOPhaseHandler_Slot2:
lb $a0, 0x1 (v0)
lb $a0, 0x1 ($v0)
bne $t7, $a0, KKOPhaseHandler_Slot3
nop
b KKOPhaseHandler_Finish
lb $t8, 0x2 (v0)
lb $t8, 0x2 ($v0)

KKOPhaseHandler_Slot3:
lb $a0, 0x2 (v0)
lb $a0, 0x2 ($v0)
bne $t7, $a0, KKOPhaseHandler_Finish
nop
b KKOPhaseHandler_Finish
Expand All @@ -181,7 +32,7 @@ KKOPhaseHandler:
KKOPhaseHandler_Finish:
sb $t8, 0x12 ($s0)
j 0x80032578
lb v0, 0x12 ($s0)
lb $v0, 0x12 ($s0)

KKOInitPhase:
lui $at, hi(KKOPhaseOrder)
Expand Down
3 changes: 2 additions & 1 deletion base-hack/include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern void populateEnemyMapData(void);
extern int getLo(void* addr);
extern int getHi(void* addr);

extern int determineShockwaveColor(actorData* shockwave);

extern int hasChunkyPhaseSlam(void);
extern void fixKRoolKong(void);

Expand All @@ -68,7 +70,6 @@ extern int correctRefillCap(int index, int player);
extern void cc_effect_handler(void);

extern void PatchCrankyCode(void);
extern void PatchKRoolCode(void);
extern void PatchBonusCode(void);
extern void kioskBugCode(void);
extern void FileScreenDLCode_Write(void);
Expand Down
14 changes: 13 additions & 1 deletion base-hack/include/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ extern void updateBarrierNumbers(void);
extern void capScreenShake(void);
extern void blockTreeClimbing(void);
extern void reenable_balloon_z(void);
extern void GoToPassword(void);
extern void GoToPassword(void);

extern void KRoolLankyPhaseFix(void);
extern void KKOPhaseHandler(void);
extern void KKOInitPhase(void);
extern void MadJackShort(void);
extern void PufftossShort(void);
extern void DogadonRematchShort(void);
extern void DilloRematchShort(void);
extern void DKPhaseShort(void);
extern void TinyPhaseShort(void);
extern void ChunkyPhaseShort(void);
extern void ChunkyPhaseAddedSave(void);
35 changes: 7 additions & 28 deletions base-hack/src/initialization/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,34 +422,6 @@ void initHack(int source) {
KongModelData[KONG_DIDDY].props_or = 0;
}
fixCutsceneModels();
if (Rando.disabled_music.pause) {
*(int*)(0x805FC890) = 0; // Pause theme
*(int*)(0x805FC89C) = 0; // Pause Start theme
}
if (Rando.disabled_music.wrinkly) {
*(int*)(0x8064F180) = 0; // Wrinkly Theme
}
if (Rando.disabled_music.transform) {
*(int*)(0x8067E9E4) = 0; // Transform Theme
*(int*)(0x8067F7C0) = 0; // Transform Theme
}
*(int*)(0x80602AAC) = 0x27A40018; // addiu $a0, $sp, 0x18
if (Rando.disabled_music.chunk_songs) {
// *(int*)(0x806025BC) = 0; // Disable `playLevelMusic` - Map Load
*(int*)(0x8061DF74) = 0; // Disable `playLevelMusic`
*(int*)(0x806DB98C) = 0; // Disable `playLevelMusic`
*(short*)(0x806034F2) = 0; // Set Japes count to 0
*(short*)(0x80603556) = 0; // Set Az Beetle count to 0
*(short*)(0x80603542) = 0; // Set Factory count to 0
*(short*)(0x8060356A) = 0; // Set Factory Car count to 0
*(short*)(0x8060351A) = 0; // Set Galleon count to 0
//*(short*)(0x80603592) = 0; // Set Isles count to 0
*(short*)(0x80603506) = 0; // Set Aztec count to 0
*(short*)(0x8060352E) = 0; // Set Galleon Seal count to 0
*(short*)(0x806035C6) = 0; // Set Fungi count to 0
*(short*)(0x8060357E) = 0; // Set Fungi Cart count to 0
*(short*)(0x806035BA) = 0; // Set TGrounds count to 0
}
if (Rando.hard_mode.lava_water) {
// Dynamic Textures
SurfaceTypeInformation[0].texture_loader = SurfaceTypeInformation[7].texture_loader;
Expand All @@ -463,6 +435,13 @@ void initHack(int source) {
SurfaceTypeInformation[3].texture_loader = SurfaceTypeInformation[6].texture_loader;
SurfaceTypeInformation[3].dl_writer = SurfaceTypeInformation[7].dl_writer; // Use lava water renderer instead of acid one to have translucency
}
if (Rando.colorblind_mode != COLORBLIND_OFF) {
writeFunction(0x8069E968, &determineShockwaveColor);
}
if (Rando.remove_oscillation_effects) {
writeFunction(0x80660994, &getOscillationDelta);
writeFunction(0x806609BC, &getOscillationDelta);
}
initSwitchsanityChanges();

SFXVolume = Rando.default_sfx_volume;
Expand Down
2 changes: 0 additions & 2 deletions base-hack/src/overlays/boss.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ void overlay_mod_boss(void) {
*(int*)(0x8002FFE8) = 0; // Control State progress patch
}
}
PatchKRoolCode();

if (Rando.music_rando_on) {
// Lower Crowd SFX Volume
*(short*)(0x80028F3E) = CROWD_VOLUME;
Expand Down
61 changes: 51 additions & 10 deletions randomizer/Patching/ASMPatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
PuzzleRando,
WinConditionComplex,
ExtraCutsceneSkips,
ExcludedSongs,
)
from randomizer.Enums.Maps import Maps
from randomizer.Lists.MapsAndExits import GetExitId, GetMapId
Expand Down Expand Up @@ -553,6 +554,32 @@ def patchAssemblyCosmetic(ROM_COPY: ROM, settings: Settings):
writeValue(ROM_COPY, 0x806FF116, Overlay.Static, crosshair_img, offset_dict)
writeValue(ROM_COPY, 0x806B78DA, Overlay.Static, crosshair_img, offset_dict)

if IsItemSelected(settings.songs_excluded, settings.excluded_songs_selected, ExcludedSongs.pause_music):
writeValue(ROM_COPY, 0x805FC890, Overlay.Static, 0, offset_dict, 4) # Pause Theme
writeValue(ROM_COPY, 0x805FC89C, Overlay.Static, 0, offset_dict, 4) # Pause Start Theme
if IsItemSelected(settings.songs_excluded, settings.excluded_songs_selected, ExcludedSongs.wrinkly):
writeValue(ROM_COPY, 0x8064F180, Overlay.Static, 0, offset_dict, 4) # Wrinkly Theme
if IsItemSelected(settings.songs_excluded, settings.excluded_songs_selected, ExcludedSongs.transformation):
writeValue(ROM_COPY, 0x8067E9E4, Overlay.Static, 0, offset_dict, 4) # Transform Theme
writeValue(ROM_COPY, 0x8067F7C0, Overlay.Static, 0, offset_dict, 4) # Transform Theme
writeValue(ROM_COPY, 0x80602AAC, Overlay.Static, 0x27A40018, offset_dict, 4) # addiu $a0, $sp, 0x18
if IsItemSelected(settings.songs_excluded, settings.excluded_songs_selected, ExcludedSongs.sub_areas):
#writeValue(ROM_COPY, 0x806025BC, Overlay.Static, 0, offset_dict, 4) # Disable `playLevelMusic` - Map Load
writeValue(ROM_COPY, 0x8061DF74, Overlay.Static, 0, offset_dict, 4) # Disable `playLevelMusic`
writeValue(ROM_COPY, 0x806DB98C, Overlay.Static, 0, offset_dict, 4) # Disable `playLevelMusic`
writeValue(ROM_COPY, 0x806034F2, Overlay.Static, 0, offset_dict) # Set Japes count to 0
writeValue(ROM_COPY, 0x80603556, Overlay.Static, 0, offset_dict) # Set Az Beetle count to 0
writeValue(ROM_COPY, 0x80603542, Overlay.Static, 0, offset_dict) # Set Factory count to 0
writeValue(ROM_COPY, 0x8060356A, Overlay.Static, 0, offset_dict) # Set Factory Car count to 0
writeValue(ROM_COPY, 0x8060351A, Overlay.Static, 0, offset_dict) # Set Galleon count to 0
#writeValue(ROM_COPY, 0x80603592, Overlay.Static, 0, offset_dict) # Set Isles count to 0
writeValue(ROM_COPY, 0x80603506, Overlay.Static, 0, offset_dict) # Set Aztec count to 0
writeValue(ROM_COPY, 0x8060352E, Overlay.Static, 0, offset_dict) # Set Galleon Seal count to 0
writeValue(ROM_COPY, 0x806035C6, Overlay.Static, 0, offset_dict) # Set Fungi count to 0
writeValue(ROM_COPY, 0x8060357E, Overlay.Static, 0, offset_dict) # Set Fungi Cart count to 0
writeValue(ROM_COPY, 0x806035BA, Overlay.Static, 0, offset_dict) # Set TGrounds count to 0


# Holiday Mode Stuff
holiday = getHoliday(settings)
if holiday == Holidays.Halloween:
Expand All @@ -574,7 +601,6 @@ def patchAssemblyCosmetic(ROM_COPY: ROM, settings: Settings):
writeValue(ROM_COPY, 0x806682DC, Overlay.Static, 0x240E0004, offset_dict, 4) # Set ground sfx to snow

if settings.colorblind_mode != ColorblindMode.off:
writeFunction(ROM_COPY, 0x8069E968, Overlay.Static, "determineShockwaveColor", offset_dict) # Shockwave handler
writeValue(ROM_COPY, 0x8069E974, Overlay.Static, 0x1000, offset_dict) # Force first option
writeValue(ROM_COPY, 0x8069E9B0, Overlay.Static, 0, offset_dict, 4) # Prevent write
writeValue(ROM_COPY, 0x8069E9B4, Overlay.Static, 0, offset_dict, 4) # Prevent write
Expand All @@ -584,10 +610,6 @@ def patchAssemblyCosmetic(ROM_COPY: ROM, settings: Settings):
ref_crosshair.writeRGBColors(ROM_COPY, offset_dict, ref_crosshair.homing, 0x806FFA76, 0x806FFA7A)
ref_crosshair.writeRGBColors(ROM_COPY, offset_dict, ref_crosshair.regular, 0x806FF0C6, 0x806FF0CA)
ref_crosshair.writeRGBColors(ROM_COPY, offset_dict, ref_crosshair.homing, 0x806FF0AA, 0x806FF0AE)
if settings.remove_water_oscillation:
writeFunction(ROM_COPY, 0x80660994, Overlay.Static, "getOscillationDelta", offset_dict)
writeFunction(ROM_COPY, 0x806609BC, Overlay.Static, "getOscillationDelta", offset_dict)

if settings.override_cosmetics:
enemy_setting = RandomModels[js.document.getElementById("random_enemy_colors").value]
else:
Expand Down Expand Up @@ -968,6 +990,30 @@ def patchAssembly(ROM_COPY, spoiler):
writeHook(ROM_COPY, 0x80600674, Overlay.Static, "updateLag", offset_dict)
writeHook(ROM_COPY, 0x806FC990, Overlay.Static, "ApplyTextRecolorHints", offset_dict)

# Boss stuff
writeHook(ROM_COPY, 0x80028CCC, Overlay.Boss, "KRoolLankyPhaseFix", offset_dict)
if IsItemSelected(settings.hard_bosses, settings.hard_bosses_selected, HardBossesSelected.kut_out_phase_rando):
writeHook(ROM_COPY, 0x80032570, Overlay.Boss, "KKOPhaseHandler", offset_dict)
writeHook(ROM_COPY, 0x80031B2C, Overlay.Boss, "KKOInitPhase", offset_dict)
writeValue(ROM_COPY, 0x8003259A, Overlay.Boss, 4, offset_dict, 2) # KKO Last Phase Check
writeValue(ROM_COPY, 0x80032566, Overlay.Boss, settings.kko_phase_order[1], offset_dict, 2) # KKO Last Phase Check
if settings.shorten_boss:
writeValue(ROM_COPY, 0x8074D3A8, Overlay.Static, 3, offset_dict) # Dillo Health 4 -> 3
writeValue(ROM_COPY, 0x8074D474, Overlay.Static, int(3 + (62 * (2 / 3))), offset_dict) # Dogadon Health 65 -> 44
writeValue(ROM_COPY, 0x8074D4B0, Overlay.Static, 3, offset_dict) # Spider Boss Health 6 -> 3
writeHook(ROM_COPY, 0x80035120, Overlay.Boss, "MadJackShort", offset_dict)
writeValue(ROM_COPY, 0x800350D2, Overlay.Boss, 2, offset_dict, 2) # Mad Jack Cutscene Memery
writeHook(ROM_COPY, 0x80029AAC, Overlay.Boss, "PufftossShort", offset_dict)
writeHook(ROM_COPY, 0x8002ACB0, Overlay.Boss, "DogadonRematchShort", offset_dict)
writeHook(ROM_COPY, 0x800257CC, Overlay.Boss, "DilloRematchShort", offset_dict)
writeValue(ROM_COPY, 0x800322BA, Overlay.Boss, 2, offset_dict, 2) # Kut Out hit limit
writeHook(ROM_COPY, 0x8002DB10, Overlay.Boss, "DKPhaseShort", offset_dict)
writeValue(ROM_COPY, 0x8002E52A, Overlay.Boss, 2, offset_dict, 2) # Diddy Phase Hit Count
writeValue(ROM_COPY, 0x8002EF02, Overlay.Boss, 2, offset_dict, 2) # Lanky Phase Hit Count
writeHook(ROM_COPY, 0x80030370, Overlay.Boss, "TinyPhaseShort", offset_dict)
writeHook(ROM_COPY, 0x800314B4, Overlay.Boss, "ChunkyPhaseShort", offset_dict)
writeHook(ROM_COPY, 0x80031378, Overlay.Boss, "ChunkyPhaseAddedSave", offset_dict)

# Change pause menu background design
writeValue(ROM_COPY, 0x806A84F4, Overlay.Static, 0, offset_dict, 4) # Enable framebuffer clear on pause menu
writeValue(ROM_COPY, 0x806A90E8, Overlay.Static, 0, offset_dict, 4) # Disable Screen Shake
Expand Down Expand Up @@ -1452,11 +1498,6 @@ def patchAssembly(ROM_COPY, spoiler):
writeFunction(ROM_COPY, 0x806E5418, Overlay.Static, "handleActionSet", offset_dict) # Instrument Play
writeFunction(ROM_COPY, 0x806E6064, Overlay.Static, "handleActionSet", offset_dict) # Gun Pull

if settings.shorten_boss:
writeValue(ROM_COPY, 0x8074D3A8, Overlay.Static, 3, offset_dict) # Dillo Health 4 -> 3
writeValue(ROM_COPY, 0x8074D474, Overlay.Static, int(3 + (62 * (2 / 3))), offset_dict) # Dogadon Health 65 -> 44
writeValue(ROM_COPY, 0x8074D4B0, Overlay.Static, 3, offset_dict) # Spider Boss Health 6 -> 3

if settings.bonus_barrel_auto_complete:
writeValue(ROM_COPY, 0x806818DE, Overlay.Static, 0x4248, offset_dict) # Make Aztec Lobby GB spawn above the trapdoor)
writeValue(ROM_COPY, 0x80681690, Overlay.Static, 0, offset_dict, 4) # Make some barrels not play a cutscene
Expand Down
Binary file modified static/patches/shrink-dk64.bps
Binary file not shown.
Loading
Loading