Skip to content

Commit 382001f

Browse files
lordlouJouramie
authored andcommitted
SMZ3: 0.4.4 backward compat client fix (ArchipelagoMW#2667)
fixed broken client compatibility with any seed generated before 0.4.4 introduced with the recent change to the message queue.
1 parent c9fb79f commit 382001f

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

worlds/smz3/Client.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ async def validate_rom(self, ctx):
4040
if rom_name is None or rom_name == bytes([0] * ROMNAME_SIZE) or rom_name[:3] != b"ZSM":
4141
return False
4242

43+
ctx.smz3_new_message_queue = rom_name[7] in b"1234567890"
4344
ctx.game = self.game
4445
ctx.items_handling = 0b101 # local items and remote start inventory
4546

@@ -53,6 +54,22 @@ async def game_watcher(self, ctx):
5354
if ctx.server is None or ctx.slot is None:
5455
# not successfully connected to a multiworld server, cannot process the game sending items
5556
return
57+
58+
send_progress_addr_ptr_offset = 0x680
59+
send_progress_size = 8
60+
send_progress_message_byte_offset = 4
61+
send_progress_addr_table_offset = 0x700
62+
recv_progress_addr_ptr_offset = 0x600
63+
recv_progress_size = 4
64+
recv_progress_addr_table_offset = 0x602
65+
if ctx.smz3_new_message_queue:
66+
send_progress_addr_ptr_offset = 0xD3C
67+
send_progress_size = 2
68+
send_progress_message_byte_offset = 0
69+
send_progress_addr_table_offset = 0xDA0
70+
recv_progress_addr_ptr_offset = 0xD36
71+
recv_progress_size = 2
72+
recv_progress_addr_table_offset = 0xD38
5673

5774
currentGame = await snes_read(ctx, SRAM_START + 0x33FE, 2)
5875
if (currentGame is not None):
@@ -69,22 +86,22 @@ async def game_watcher(self, ctx):
6986
ctx.finished_game = True
7087
return
7188

72-
data = await snes_read(ctx, SMZ3_RECV_PROGRESS_ADDR + 0xD3C, 4)
89+
data = await snes_read(ctx, SMZ3_RECV_PROGRESS_ADDR + send_progress_addr_ptr_offset, 4)
7390
if data is None:
7491
return
7592

7693
recv_index = data[0] | (data[1] << 8)
7794
recv_item = data[2] | (data[3] << 8)
7895

7996
while (recv_index < recv_item):
80-
item_address = recv_index * 2
81-
message = await snes_read(ctx, SMZ3_RECV_PROGRESS_ADDR + 0xDA0 + item_address, 2)
82-
is_z3_item = ((message[1] & 0x80) != 0)
83-
masked_part = (message[1] & 0x7F) if is_z3_item else message[1]
84-
item_index = ((message[0] | (masked_part << 8)) >> 3) + (256 if is_z3_item else 0)
97+
item_address = recv_index * send_progress_size
98+
message = await snes_read(ctx, SMZ3_RECV_PROGRESS_ADDR + send_progress_addr_table_offset + item_address, send_progress_size)
99+
is_z3_item = ((message[send_progress_message_byte_offset+1] & 0x80) != 0)
100+
masked_part = (message[send_progress_message_byte_offset+1] & 0x7F) if is_z3_item else message[send_progress_message_byte_offset+1]
101+
item_index = ((message[send_progress_message_byte_offset] | (masked_part << 8)) >> 3) + (256 if is_z3_item else 0)
85102

86103
recv_index += 1
87-
snes_buffered_write(ctx, SMZ3_RECV_PROGRESS_ADDR + 0xD3C, bytes([recv_index & 0xFF, (recv_index >> 8) & 0xFF]))
104+
snes_buffered_write(ctx, SMZ3_RECV_PROGRESS_ADDR + send_progress_addr_ptr_offset, bytes([recv_index & 0xFF, (recv_index >> 8) & 0xFF]))
88105

89106
from .TotalSMZ3.Location import locations_start_id
90107
from . import convertLocSMZ3IDToAPID
@@ -95,7 +112,7 @@ async def game_watcher(self, ctx):
95112
snes_logger.info(f'New Check: {location} ({len(ctx.locations_checked)}/{len(ctx.missing_locations) + len(ctx.checked_locations)})')
96113
await ctx.send_msgs([{"cmd": 'LocationChecks', "locations": [location_id]}])
97114

98-
data = await snes_read(ctx, SMZ3_RECV_PROGRESS_ADDR + 0xD36, 4)
115+
data = await snes_read(ctx, SMZ3_RECV_PROGRESS_ADDR + recv_progress_addr_ptr_offset, 4)
99116
if data is None:
100117
return
101118

@@ -107,9 +124,12 @@ async def game_watcher(self, ctx):
107124
item_id = item.item - items_start_id
108125

109126
player_id = item.player if item.player < SMZ3_ROM_PLAYER_LIMIT else 0
110-
snes_buffered_write(ctx, SMZ3_RECV_PROGRESS_ADDR + item_out_ptr * 2, bytes([player_id, item_id]))
127+
snes_buffered_write(ctx,
128+
SMZ3_RECV_PROGRESS_ADDR + item_out_ptr * recv_progress_size,
129+
bytes([player_id, item_id]) if ctx.smz3_new_message_queue else
130+
bytes([player_id & 0xFF, (player_id >> 8) & 0xFF, item_id & 0xFF, (item_id >> 8) & 0xFF]))
111131
item_out_ptr += 1
112-
snes_buffered_write(ctx, SMZ3_RECV_PROGRESS_ADDR + 0xD38, bytes([item_out_ptr & 0xFF, (item_out_ptr >> 8) & 0xFF]))
132+
snes_buffered_write(ctx, SMZ3_RECV_PROGRESS_ADDR + recv_progress_addr_table_offset, bytes([item_out_ptr & 0xFF, (item_out_ptr >> 8) & 0xFF]))
113133
logging.info('Received %s from %s (%s) (%d/%d in list)' % (
114134
color(ctx.item_names[item.item], 'red', 'bold'), color(ctx.player_names[item.player], 'yellow'),
115135
ctx.location_names[item.location], item_out_ptr, len(ctx.items_received)))

worlds/smz3/TotalSMZ3/Patch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ def WriteGameTitle(self):
616616
"H" if self.myWorld.Config.SMLogic == Config.SMLogic.Hard else \
617617
"X"
618618

619-
self.title = f"ZSM{Patch.Major}{Patch.Minor}{Patch.Patch}{z3Glitch}{smGlitch}{self.myWorld.Id}{self.seed:08x}".ljust(21)[:21]
619+
from Utils import __version__
620+
self.title = f"ZSM{Patch.Major}{Patch.Minor}{Patch.Patch}{__version__.replace('.', '')[0:3]}{z3Glitch}{smGlitch}{self.myWorld.Id}{self.seed:08x}".ljust(21)[:21]
620621
self.patches.append((Snes(0x00FFC0), bytearray(self.title, 'utf8')))
621622
self.patches.append((Snes(0x80FFC0), bytearray(self.title, 'utf8')))
622623

0 commit comments

Comments
 (0)