@@ -47,6 +47,8 @@ class CommandID(IntEnum):
4747 """
4848 IDs for all PC -> Wii commands.
4949 """
50+ # default command id
51+ NONE = - 1
5052
5153 # PC client is attempting to connect
5254 CONNECT = 0
@@ -60,6 +62,9 @@ class CommandID(IntEnum):
6062 # PC client is sending an item
6163 ITEM = auto ()
6264
65+ # PC client is sending a request for location data
66+ LOCATION = auto ()
67+
6368# =============================================================================#
6469# AsyncUDPProtocol #
6570# =============================================================================#
@@ -104,6 +109,8 @@ def __init__(self, wii_ip, port=WII_PORT):
104109 self .current_request : Optional [CommandRequest ] = None
105110 self .queue_processor_task = None
106111
112+ self .most_recent_packet_data = []
113+
107114
108115 async def connect (self ):
109116 """
@@ -156,6 +163,7 @@ def handle_response(self, data):
156163 """
157164 Handle incoming UDP response
158165 """
166+ self .most_recent_packet_data = data
159167
160168 if self .current_request and not self .current_request .future .done ():
161169 self .current_request .future .set_result (data )
@@ -255,11 +263,11 @@ def close(self):
255263 self .transport = None
256264
257265
258- async def send_packet (self , data , packet_type_id , timeout = 2 ):
266+ async def send_packet (self , data , packet_type_id = CommandID . NONE , timeout = 2 ):
259267 """Send a single packet to the wii client"""
260268
261269 packet = bytearray ()
262- packet += struct .pack (">B" , packet_type_id ) # id: u8
270+ packet += struct .pack (">B" , packet_type_id ) # id: u8
263271 packet += data # data: byte[]
264272
265273 if len (packet ) > 512 :
@@ -269,7 +277,7 @@ async def send_packet(self, data, packet_type_id, timeout=2):
269277
270278 # expect 0xAA byte for ack
271279 response = await self ._send_command_queued (packet , timeout )
272- if len (response ) == 1 and response [0 ] == 0xAA :
280+ if ( len (response ) == 1 and response [0 ] == 0xAA ) or ( packet_type_id == CommandID . LOCATION and len ( response ) > 0 ) :
273281 return True
274282
275283 raise Exception (f"Packet went unacknowledged: { packet } " )
@@ -350,6 +358,21 @@ def _cmd_debug_print(self, msg = "dummy") -> None:
350358
351359 Utils .async_start (self .ctx .wii_client .send_print_cmd (args ))
352360
361+ def _cmd_check_locations (self , msg = "dummy" ) -> None :
362+ """
363+ Send a check location command for debugging purposes.
364+
365+ @param self: WSRCommandProcessor
366+ @param msg: does nothing
367+ """
368+ if not isinstance (self .ctx , WSRContext ):
369+ logger .info ("Please connect to the wii first" )
370+
371+ if not DEBUG_MODE :
372+ return
373+
374+ Utils .async_start (self .ctx .check_locations ())
375+
353376# =============================================================================#
354377# Game context #
355378# =============================================================================#
@@ -505,9 +528,14 @@ async def check_locations(self) -> None:
505528
506529 @param self: The WSR client context.
507530 """
531+ if not isinstance (self .wii_client , WiiClient ):
532+ logger .info ("Please connect to the wii first" )
533+ return
534+
535+ response = await self .wii_client .send_packet (bytes (), packet_type_id = CommandID .LOCATION )
508536
509- # TODO: Not yet implemented
510- pass
537+ logger . info ( f"Location Data in bytes: { self . wii_client . most_recent_packet_data } " )
538+
511539
512540
513541 async def _give_item (self , item_name : str ) -> bool :
0 commit comments