From f3d966897f3bf4111bd548fc562d9ea3004a4027 Mon Sep 17 00:00:00 2001 From: PoryGone <98504756+PoryGone@users.noreply.github.com> Date: Thu, 28 Jul 2022 19:13:00 -0400 Subject: [PATCH] Prevent Krematoa Crash (#832) * Prevent Krematoa Crash, add crash robustness * Remove print statements * Don't remove ctx.rom if save file dies * Consolidate logic for readability --- worlds/dkc3/Client.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/worlds/dkc3/Client.py b/worlds/dkc3/Client.py index 12643a5f..8ac20131 100644 --- a/worlds/dkc3/Client.py +++ b/worlds/dkc3/Client.py @@ -77,9 +77,9 @@ async def dkc3_game_watcher(ctx: Context): # DKC3_TODO: Handle non-included checks new_checks.append(loc_id) - save_file_name = await snes_read(ctx, DKC3_FILE_NAME_ADDR, 0x5) - if save_file_name is None or save_file_name[0] == 0x00: - # We have somehow exited the save file + verify_save_file_name = await snes_read(ctx, DKC3_FILE_NAME_ADDR, 0x5) + if verify_save_file_name is None or verify_save_file_name[0] == 0x00 or verify_save_file_name != save_file_name: + # We have somehow exited the save file (or worse) return rom = await snes_read(ctx, DKC3_ROMHASH_START, ROMHASH_SIZE) @@ -116,17 +116,18 @@ async def dkc3_game_watcher(ctx: Context): # Handle Coin Displays current_level = await snes_read(ctx, WRAM_START + 0x5E3, 0x5) - if item.item == 0xDC3002 and (current_level[0] == 0x0A and current_level[2] == 0x00 and current_level[4] == 0x03): + overworld_locked = ((await snes_read(ctx, WRAM_START + 0x5FC, 0x1))[0] == 0x01) + if item.item == 0xDC3002 and not overworld_locked and (current_level[0] == 0x0A and current_level[2] == 0x00 and current_level[4] == 0x03): # Bazaar and Barter item_count = await snes_read(ctx, WRAM_START + 0xB02, 0x1) new_item_count = item_count[0] + 1 snes_buffered_write(ctx, WRAM_START + 0xB02, bytes([new_item_count])) - elif item.item == 0xDC3002 and current_level[0] == 0x04: + elif item.item == 0xDC3002 and not overworld_locked and current_level[0] == 0x04: # Swanky item_count = await snes_read(ctx, WRAM_START + 0xA26, 0x1) new_item_count = item_count[0] + 1 snes_buffered_write(ctx, WRAM_START + 0xA26, bytes([new_item_count])) - elif item.item == 0xDC3003 and (current_level[0] == 0x0A and current_level[2] == 0x08 and current_level[4] == 0x01): + elif item.item == 0xDC3003 and not overworld_locked and (current_level[0] == 0x0A and current_level[2] == 0x08 and current_level[4] == 0x01): # Boomer item_count = await snes_read(ctx, WRAM_START + 0xB02, 0x1) new_item_count = item_count[0] + 1