Skip to content

Commit 488ad3c

Browse files
authored
Merge pull request ArchipelagoMW#4 from lilDavid/mzm_client_fix
Client fixes
2 parents a8831cc + b662c85 commit 488ad3c

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

worlds/mzm/client.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525

2626
def read(address: int, length: int, *, align: int = 1):
27-
assert address % align == 0, f'address: 0x{address:07x}, align: {align}'
28-
return (address, length, 'System Bus')
27+
assert address % align == 0, f"address: 0x{address:07x}, align: {align}"
28+
return (address, length, "System Bus")
2929

3030
def read8(address: int):
3131
return read(address, 1)
@@ -38,32 +38,32 @@ def read32(address: int):
3838

3939

4040
def write(address: int, value: bytes, *, align: int = 1):
41-
assert address % align == 0, f'address: 0x{address:07x}, align: {align}'
42-
return (address, value, 'System Bus')
41+
assert address % align == 0, f"address: 0x{address:07x}, align: {align}"
42+
return (address, value, "System Bus")
4343

4444
def write8(address: int, value: int):
45-
return write(address, value.to_bytes(1, 'little'))
45+
return write(address, value.to_bytes(1, "little"))
4646

4747
def write16(address: int, value: int):
48-
return write(address, value.to_bytes(2, 'little'), align=2)
48+
return write(address, value.to_bytes(2, "little"), align=2)
4949

5050
def write32(address: int, value: int):
51-
return write(address, value.to_bytes(4, 'little'), align=4)
51+
return write(address, value.to_bytes(4, "little"), align=4)
5252

5353

5454
guard8 = write8
5555
guard16 = write16
5656

5757

5858
def next_int(iterator: Iterator[bytes]) -> int:
59-
return int.from_bytes(next(iterator), 'little')
59+
return int.from_bytes(next(iterator), "little")
6060

6161

6262
# itertools.batched from Python 3.12
6363
# https://docs.python.org/3.11/library/itertools.html#itertools-recipes
6464
def batched(iterable, n):
6565
if n < 1:
66-
raise ValueError('n must be at least 1')
66+
raise ValueError("n must be at least 1")
6767
it = iter(iterable)
6868
while batch := tuple(itertools.islice(it, n)):
6969
yield batch
@@ -105,13 +105,13 @@ def batched(iterable, n):
105105

106106

107107
def cmd_deathlink(self):
108-
'''Toggle death link from client. Overrides default setting.'''
108+
"""Toggle death link from client. Overrides default setting."""
109109

110110
client_handler = self.ctx.client_handler
111111
client_handler.death_link.enabled = not client_handler.death_link.enabled
112112
Utils.async_start(
113113
self.ctx.update_death_link(client_handler.death_link.enabled),
114-
name='Update Death Link'
114+
name="Update Death Link"
115115
)
116116

117117

@@ -122,10 +122,10 @@ class DeathLinkCtx:
122122
sent_this_death: bool = False
123123

124124
def __repr__(self):
125-
return (f'{type(self)} {{ enabled: {self.enabled}, '
126-
f'update_pending: {self.update_pending}, '
127-
f'pending: {self.pending}, '
128-
f'sent_this_death: {self.sent_this_death} }}')
125+
return (f"{type(self)} {{ enabled: {self.enabled}, "
126+
f"update_pending: {self.update_pending}, "
127+
f"pending: {self.pending}, "
128+
f"sent_this_death: {self.sent_this_death} }}")
129129

130130
def __str__(self):
131131
return repr(self)
@@ -149,7 +149,7 @@ class ZMConstants:
149149
gGameModeSub1 = get_symbol("gGameModeSub1")
150150
gPreventMovementTimer = get_symbol("gPreventMovementTimer")
151151
gEquipment = get_symbol("gEquipment")
152-
gEventsTriggered = get_symbol("gEventsTriggered");
152+
gEventsTriggered = get_symbol("gEventsTriggered")
153153
gRandoLocationBitfields = get_symbol("gRandoLocationBitfields")
154154
gIncomingItemId = get_symbol("gIncomingItemId")
155155
gMultiworldItemCount = get_symbol("gMultiworldItemCount")
@@ -187,16 +187,16 @@ async def validate_rom(self, client_ctx: BizHawkClientContext) -> bool:
187187
return False # Should verify on the next pass
188188

189189
game_name = next(read_result).decode("ascii")
190-
slot_name_bytes = next(read_result).rstrip(b'\0')
191-
seed_name_bytes = next(read_result).rstrip(b'\0')
190+
slot_name_bytes = next(read_result).rstrip(b"\0")
191+
seed_name_bytes = next(read_result).rstrip(b"\0")
192192

193193
if game_name != "ZEROMISSIONE":
194194
return False
195195

196196
# Check if we can read the slot name. Doing this here instead of set_auth as a protection against
197197
# validating a ROM where there's no slot name to read.
198198
try:
199-
self.rom_slot_name = slot_name_bytes.decode('utf-8')
199+
self.rom_slot_name = slot_name_bytes.decode("utf-8")
200200
except UnicodeDecodeError:
201201
logger.info("Could not read slot name from ROM. Are you sure this ROM matches this client version?")
202202
return False
@@ -205,12 +205,12 @@ async def validate_rom(self, client_ctx: BizHawkClientContext) -> bool:
205205
client_ctx.items_handling = 0b001
206206
client_ctx.want_slot_data = True
207207
try:
208-
client_ctx.seed_name = seed_name_bytes.decode('utf-8')
208+
client_ctx.seed_name = seed_name_bytes.decode("utf-8")
209209
except UnicodeDecodeError:
210-
logger.info('Could not determine seed name from ROM. Are you sure this ROM matches this client version?')
210+
logger.info("Could not determine seed name from ROM. Are you sure this ROM matches this client version?")
211211
return False
212212

213-
client_ctx.command_processor.commands['deathlink'] = cmd_deathlink
213+
client_ctx.command_processor.commands["deathlink"] = cmd_deathlink
214214
self.death_link = DeathLinkCtx()
215215

216216
self.dc_pending = False
@@ -305,8 +305,8 @@ async def game_watcher(self, client_ctx: BizHawkClientContext) -> None:
305305

306306
if gMainGameMode in (ZMConstants.GM_CHOZODIA_ESCAPE, ZMConstants.GM_CREDITS) and not client_ctx.finished_game:
307307
await client_ctx.send_msgs([{
308-
'cmd': 'StatusUpdate',
309-
'status': ClientStatus.CLIENT_GOAL
308+
"cmd": "StatusUpdate",
309+
"status": ClientStatus.CLIENT_GOAL
310310
}])
311311

312312
if self.local_set_events != set_events and client_ctx.slot is not None:
@@ -315,11 +315,11 @@ async def game_watcher(self, client_ctx: BizHawkClientContext) -> None:
315315
if set_events[flag]:
316316
event_bitfield |= 1 << i
317317
await client_ctx.send_msgs([{
318-
'cmd': 'Set',
319-
'key': f'mzm_events_{client_ctx.team}_{client_ctx.slot}',
320-
'default': 0,
321-
'want_reply': False,
322-
'operations': [{'operation': 'or', 'value': event_bitfield}]
318+
"cmd": "Set",
319+
"key": f"mzm_events_{client_ctx.team}_{client_ctx.slot}",
320+
"default": 0,
321+
"want_reply": False,
322+
"operations": [{"operation": "or", "value": event_bitfield}]
323323
}])
324324
self.local_set_events = set_events
325325

@@ -370,15 +370,15 @@ async def game_watcher(self, client_ctx: BizHawkClientContext) -> None:
370370
return
371371

372372
def on_package(self, ctx: BizHawkClientContext, cmd: str, args: dict) -> None:
373-
if cmd == 'Connected':
374-
if args['slot_data'].get('death_link'):
373+
if cmd == "Connected":
374+
if args["slot_data"].get("death_link"):
375375
self.death_link.enabled = True
376376
self.death_link.update_pending = True
377-
if cmd == 'RoomInfo':
378-
if ctx.seed_name and ctx.seed_name != args['seed_name']:
377+
if cmd == "RoomInfo":
378+
if ctx.seed_name and ctx.seed_name != args["seed_name"]:
379379
# CommonClient's on_package displays an error to the user in this case, but connection is not cancelled.
380380
self.dc_pending = True
381-
if cmd == 'Bounced':
382-
tags = args.get('tags', [])
383-
if 'DeathLink' in tags and args['data']['source'] != ctx.auth:
381+
if cmd == "Bounced":
382+
tags = args.get("tags", [])
383+
if "DeathLink" in tags and args["data"]["source"] != ctx.auth:
384384
self.death_link.pending = True

worlds/mzm/data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _get_symbols():
9898

9999
symbol_data = data_path("extracted_symbols.json").decode("utf-8")
100100
symbols = json.loads(symbol_data)
101-
ram_symbols = symbols["iwram"]
101+
ram_symbols = symbols["ewram"] | symbols["iwram"]
102102
rom_symbols = symbols["rom"]
103103

104104

0 commit comments

Comments
 (0)