Skip to content

Commit ca8f6c2

Browse files
committed
Post-Merge Cleanup #2
1 parent 4a8ba05 commit ca8f6c2

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

SNIClient.py

+22-31
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ def on_deathlink(self, data: dict):
156156
self.killing_player_task = asyncio.create_task(deathlink_kill_player(self))
157157
super(Context, self).on_deathlink(data)
158158

159+
def handle_deathlink_state(self, currently_dead: bool):
160+
# in this state we only care about triggering a death send
161+
if self.death_state == DeathState.alive:
162+
if currently_dead:
163+
self.death_state = DeathState.dead
164+
await self.send_death()
165+
# in this state we care about confirming a kill, to move state to dead
166+
elif self.death_state == DeathState.killing_player:
167+
# this is being handled in deathlink_kill_player(ctx) already
168+
pass
169+
# in this state we wait until the player is alive again
170+
elif self.death_state == DeathState.dead:
171+
if not currently_dead:
172+
self.death_state = DeathState.alive
173+
159174

160175
async def deathlink_kill_player(ctx: Context):
161176
ctx.death_state = DeathState.killing_player
@@ -581,7 +596,7 @@ async def verify_snes_app(socket):
581596
await socket.send(dumps(AppVersion_Request))
582597

583598
app: str = loads(await socket.recv())["Results"][0]
584-
if not "SNI" in app:
599+
if "SNI" not in app:
585600
snes_logger.warning(f"Warning: Did not find SNI as the endpoint, instead {app} was found.")
586601

587602

@@ -920,19 +935,7 @@ async def game_watcher(ctx: Context):
920935
gamemode = await snes_read(ctx, WRAM_START + 0x10, 1)
921936
if "DeathLink" in ctx.tags and gamemode and ctx.last_death_link + 1 < time.time():
922937
currently_dead = gamemode[0] in DEATH_MODES
923-
# in this state we only care about triggering a death send
924-
if ctx.death_state == DeathState.alive:
925-
if currently_dead:
926-
ctx.death_state = DeathState.dead
927-
await ctx.send_death()
928-
# in this state we care about confirming a kill, to move state to dead
929-
elif ctx.death_state == DeathState.killing_player:
930-
# this is being handled in deathlink_kill_player(ctx) already
931-
pass
932-
# in this state we wait until the player is alive again
933-
elif ctx.death_state == DeathState.dead:
934-
if not currently_dead:
935-
ctx.death_state = DeathState.alive
938+
ctx.handle_deathlink_state(currently_dead)
936939

937940
gameend = await snes_read(ctx, SAVEDATA_START + 0x443, 1)
938941
game_timer = await snes_read(ctx, SAVEDATA_START + 0x42E, 4)
@@ -1001,19 +1004,7 @@ async def game_watcher(ctx: Context):
10011004
gamemode = await snes_read(ctx, WRAM_START + 0x0998, 1)
10021005
if "DeathLink" in ctx.tags and gamemode and ctx.last_death_link + 1 < time.time():
10031006
currently_dead = gamemode[0] in SM_DEATH_MODES
1004-
# in this state we only care about triggering a death send
1005-
if ctx.death_state == DeathState.alive:
1006-
if currently_dead:
1007-
ctx.death_state = DeathState.dead
1008-
await ctx.send_death()
1009-
# in this state we care about confirming a kill, to move state to dead
1010-
elif ctx.death_state == DeathState.killing_player:
1011-
# this is being handled in deathlink_kill_player(ctx) already
1012-
pass
1013-
# in this state we wait until the player is alive again
1014-
elif ctx.death_state == DeathState.dead:
1015-
if not currently_dead:
1016-
ctx.death_state = DeathState.alive
1007+
ctx.handle_deathlink_state(currently_dead)
10171008
if gamemode is not None and gamemode[0] in SM_ENDGAME_MODES:
10181009
if not ctx.finished_game:
10191010
await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}])
@@ -1030,10 +1021,9 @@ async def game_watcher(ctx: Context):
10301021
while (recv_index < recv_item):
10311022
itemAdress = recv_index * 8
10321023
message = await snes_read(ctx, SM_RECV_PROGRESS_ADDR + 0x700 + itemAdress, 8)
1033-
worldId = message[0] | (message[1] << 8)
1034-
itemId = message[2] | (message[3] << 8)
1024+
# worldId = message[0] | (message[1] << 8) # unused
1025+
# itemId = message[2] | (message[3] << 8) # unused
10351026
itemIndex = (message[4] | (message[5] << 8)) >> 3
1036-
seq = recv_index
10371027

10381028
recv_index += 1
10391029
snes_buffered_write(ctx, SM_RECV_PROGRESS_ADDR + 0x680, bytes([recv_index & 0xFF, (recv_index >> 8) & 0xFF]))
@@ -1050,7 +1040,7 @@ async def game_watcher(ctx: Context):
10501040
if data is None:
10511041
continue
10521042

1053-
recv_itemOutPtr = data[0] | (data[1] << 8)
1043+
# recv_itemOutPtr = data[0] | (data[1] << 8) # unused
10541044
itemOutPtr = data[2] | (data[3] << 8)
10551045

10561046
from worlds.sm.Items import items_start_id
@@ -1067,6 +1057,7 @@ async def game_watcher(ctx: Context):
10671057
ctx.location_name_getter(item.location), itemOutPtr, len(ctx.items_received)))
10681058
await snes_flush_writes(ctx)
10691059

1060+
10701061
async def run_game(romfile):
10711062
auto_start = Utils.get_options()["lttp_options"].get("rom_start", True)
10721063
if auto_start is True:

0 commit comments

Comments
 (0)