@@ -156,6 +156,21 @@ def on_deathlink(self, data: dict):
156
156
self .killing_player_task = asyncio .create_task (deathlink_kill_player (self ))
157
157
super (Context , self ).on_deathlink (data )
158
158
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
+
159
174
160
175
async def deathlink_kill_player (ctx : Context ):
161
176
ctx .death_state = DeathState .killing_player
@@ -581,7 +596,7 @@ async def verify_snes_app(socket):
581
596
await socket .send (dumps (AppVersion_Request ))
582
597
583
598
app : str = loads (await socket .recv ())["Results" ][0 ]
584
- if not "SNI" in app :
599
+ if "SNI" not in app :
585
600
snes_logger .warning (f"Warning: Did not find SNI as the endpoint, instead { app } was found." )
586
601
587
602
@@ -920,19 +935,7 @@ async def game_watcher(ctx: Context):
920
935
gamemode = await snes_read (ctx , WRAM_START + 0x10 , 1 )
921
936
if "DeathLink" in ctx .tags and gamemode and ctx .last_death_link + 1 < time .time ():
922
937
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 )
936
939
937
940
gameend = await snes_read (ctx , SAVEDATA_START + 0x443 , 1 )
938
941
game_timer = await snes_read (ctx , SAVEDATA_START + 0x42E , 4 )
@@ -1001,19 +1004,7 @@ async def game_watcher(ctx: Context):
1001
1004
gamemode = await snes_read (ctx , WRAM_START + 0x0998 , 1 )
1002
1005
if "DeathLink" in ctx .tags and gamemode and ctx .last_death_link + 1 < time .time ():
1003
1006
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 )
1017
1008
if gamemode is not None and gamemode [0 ] in SM_ENDGAME_MODES :
1018
1009
if not ctx .finished_game :
1019
1010
await ctx .send_msgs ([{"cmd" : "StatusUpdate" , "status" : ClientStatus .CLIENT_GOAL }])
@@ -1030,10 +1021,9 @@ async def game_watcher(ctx: Context):
1030
1021
while (recv_index < recv_item ):
1031
1022
itemAdress = recv_index * 8
1032
1023
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
1035
1026
itemIndex = (message [4 ] | (message [5 ] << 8 )) >> 3
1036
- seq = recv_index
1037
1027
1038
1028
recv_index += 1
1039
1029
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):
1050
1040
if data is None :
1051
1041
continue
1052
1042
1053
- recv_itemOutPtr = data [0 ] | (data [1 ] << 8 )
1043
+ # recv_itemOutPtr = data[0] | (data[1] << 8) # unused
1054
1044
itemOutPtr = data [2 ] | (data [3 ] << 8 )
1055
1045
1056
1046
from worlds .sm .Items import items_start_id
@@ -1067,6 +1057,7 @@ async def game_watcher(ctx: Context):
1067
1057
ctx .location_name_getter (item .location ), itemOutPtr , len (ctx .items_received )))
1068
1058
await snes_flush_writes (ctx )
1069
1059
1060
+
1070
1061
async def run_game (romfile ):
1071
1062
auto_start = Utils .get_options ()["lttp_options" ].get ("rom_start" , True )
1072
1063
if auto_start is True :
0 commit comments