Skip to content

Commit

Permalink
Handle Auto-tracking current room
Browse files Browse the repository at this point in the history
  • Loading branch information
PoryGone committed Jan 9, 2024
1 parent 0f707fe commit 22be7ae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
61 changes: 48 additions & 13 deletions worlds/smw/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@
SMW_BLOCKSANITY_ACTIVE_ADDR = ROM_START + 0x01BFAB


SMW_GAME_STATE_ADDR = WRAM_START + 0x100
SMW_MARIO_STATE_ADDR = WRAM_START + 0x71
SMW_BOSS_STATE_ADDR = WRAM_START + 0xD9B
SMW_ACTIVE_BOSS_ADDR = WRAM_START + 0x13FC
SMW_CURRENT_LEVEL_ADDR = WRAM_START + 0x13BF
SMW_MESSAGE_BOX_ADDR = WRAM_START + 0x1426
SMW_BONUS_STAR_ADDR = WRAM_START + 0xF48
SMW_EGG_COUNT_ADDR = WRAM_START + 0x1F24
SMW_BOSS_COUNT_ADDR = WRAM_START + 0x1F26
SMW_NUM_EVENTS_ADDR = WRAM_START + 0x1F2E
SMW_SFX_ADDR = WRAM_START + 0x1DFC
SMW_PAUSE_ADDR = WRAM_START + 0x13D4
SMW_MESSAGE_QUEUE_ADDR = WRAM_START + 0xC391
SMW_GAME_STATE_ADDR = WRAM_START + 0x100
SMW_MARIO_STATE_ADDR = WRAM_START + 0x71
SMW_BOSS_STATE_ADDR = WRAM_START + 0xD9B
SMW_ACTIVE_BOSS_ADDR = WRAM_START + 0x13FC
SMW_CURRENT_LEVEL_ADDR = WRAM_START + 0x13BF
SMW_CURRENT_SUBLEVEL_ADDR = WRAM_START + 0x10B
SMW_MESSAGE_BOX_ADDR = WRAM_START + 0x1426
SMW_BONUS_STAR_ADDR = WRAM_START + 0xF48
SMW_EGG_COUNT_ADDR = WRAM_START + 0x1F24
SMW_BOSS_COUNT_ADDR = WRAM_START + 0x1F26
SMW_NUM_EVENTS_ADDR = WRAM_START + 0x1F2E
SMW_SFX_ADDR = WRAM_START + 0x1DFC
SMW_PAUSE_ADDR = WRAM_START + 0x13D4
SMW_MESSAGE_QUEUE_ADDR = WRAM_START + 0xC391

SMW_RECV_PROGRESS_ADDR = WRAM_START + 0x1A00E

Expand Down Expand Up @@ -129,6 +130,9 @@ async def validate_rom(self, ctx):
if death_link:
await ctx.update_death_link(bool(death_link[0] & 0b1))

if ctx.rom != rom_name:
ctx.current_sublevel_value = 0

ctx.rom = rom_name

return True
Expand Down Expand Up @@ -274,6 +278,7 @@ async def game_watcher(self, ctx):
elif game_state[0] < 0x0B:
# We haven't loaded a save file
ctx.message_queue = []
ctx.current_sublevel_value = 0
return
elif mario_state[0] in SMW_INVALID_MARIO_STATES:
# Mario can't come to the phone right now
Expand Down Expand Up @@ -433,8 +438,38 @@ async def game_watcher(self, ctx):
f'New Check: {location} ({len(ctx.locations_checked)}/{len(ctx.missing_locations) + len(ctx.checked_locations)})')
await ctx.send_msgs([{"cmd": 'LocationChecks', "locations": [new_check_id]}])

# Send Current Room for Tracker
current_sublevel_data = await snes_read(ctx, SMW_CURRENT_SUBLEVEL_ADDR, 2)
current_sublevel_value = current_sublevel_data[0]+(current_sublevel_data[1]<<8)

if game_state[0] != 0x14:
current_sublevel_value = 0

if ctx.current_sublevel_value != current_sublevel_value:
ctx.current_sublevel_value = current_sublevel_value

# Send level id data to tracker
print("Sending Msg ", f"smw_curlevelid_{ctx.team}_{ctx.slot}")
await ctx.send_msgs(
[
{
"cmd": "Set",
"key": f"smw_curlevelid_{ctx.team}_{ctx.slot}",
"default": 0,
"want_reply": False,
"operations": [
{
"operation": "replace",
"value": ctx.current_sublevel_value,
}
],
}
]
)

if game_state[0] != 0x14:
# Don't receive items or collect locations outside of in-level mode
ctx.current_sublevel_value = 0
return

if boss_state[0] in SMW_BOSS_STATES:
Expand Down
4 changes: 2 additions & 2 deletions worlds/smw/Names/ItemName.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
red_switch_palace = "Red Switch Palace"
blue_switch_palace = "Blue Switch Palace"

# Special world clear flag definition
special_world_clear = "Special World Clear"
# Special Zone clear flag definition
special_world_clear = "Special Zone Clear"

# Trap Definitions
ice_trap = "Ice Trap"
Expand Down
4 changes: 2 additions & 2 deletions worlds/smw/Rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
0xBC000F: [0x1F27, 0x1, 0x1C], # Green Switch Palace
0xBC0010: [0x1F2A, 0x1, 0x1C], # Red Switch Palace
0xBC0011: [0x1F29, 0x1, 0x1C], # Blue Switch Palace
0xBC001B: [0x1FFF, 0x80, 0x39] # Special World Clear
0xBC001B: [0x1FFF, 0x80, 0x39] # Special Zone Clear
}

trap_rom_data = {
Expand Down Expand Up @@ -2793,7 +2793,7 @@ def patch_rom(world: World, rom, player, active_level_dict):

handle_uncompressed_player_gfx(rom)

# Handle special world clear flag
# Handle Special Zone Clear flag
rom.write_bytes(0x02A74, bytearray([0xFF, 0x1F]))
rom.write_bytes(0x09826, bytearray([0xFF, 0x1F]))
rom.write_bytes(0x0B9CD, bytearray([0xFF, 0x1F]))
Expand Down

0 comments on commit 22be7ae

Please sign in to comment.