@@ -66,13 +66,27 @@ async def wait_for_pj64(self):
6666 await asyncio .sleep (1.0 )
6767 pass
6868
69+ def check_safe_gameplay (self ):
70+ current_gamemode = self .n64_client .read_u8 (DK64MemoryMap .CurrentGamemode )
71+ next_gamemode = self .n64_client .read_u8 (DK64MemoryMap .NextGamemode )
72+ return current_gamemode in [6 , 0xD ] and next_gamemode in [6 , 0xD ]
73+
74+ def safe_to_send (self ):
75+ countdown_value = self .n64_client .read_u8 (self .memory_pointer + DK64MemoryMap .safety_text_timer )
76+ return countdown_value == 0
77+
6978 async def validate_client_connection (self ):
7079 if not self .memory_pointer :
7180 self .memory_pointer = self .n64_client .read_u32 (DK64MemoryMap .memory_pointer )
7281 self .n64_client .write_u8 (self .memory_pointer + DK64MemoryMap .connection , 0xFF )
7382
74- async def wait_and_init_tracker (self ):
75- await self .wait_for_game_ready ()
83+
84+
85+ def send_message (self , item_name , player_name , event_type = "from" ):
86+ stripped_item_name = "" .join (e for e in item_name if str (e ).isalnum () or str (e ) == " " )
87+ stripped_player_name = "" .join (e for e in player_name if str (e ).isalnum () or str (e ) == " " )
88+ self .n64_client .write_bytestring (self .memory_pointer + DK64MemoryMap .fed_string , f"{ stripped_item_name } " )
89+ self .n64_client .write_bytestring (self .memory_pointer + DK64MemoryMap .fed_subtitle , f"{ event_type } { stripped_player_name } " )
7690
7791 async def recved_item_from_ap (self , item_id , item_name , from_player , next_index ):
7892 # Don't allow getting an item until you've got your first check
@@ -88,12 +102,8 @@ async def recved_item_from_ap(self, item_id, item_name, from_player, next_index)
88102 await asyncio .sleep (0.1 )
89103 status = self .safe_to_send ()
90104 next_index += 1
91- # Strip out special characters from item name
92- stripped_item_name = "" .join (e for e in item_name if str (e ).isalnum () or str (e ) == " " )
93- stripped_player_name = "" .join (e for e in from_player if str (e ).isalnum () or str (e ) == " " )
94105 self .n64_client .write_u8 (self .memory_pointer + DK64MemoryMap .counter_offset , next_index )
95- self .n64_client .write_bytestring (self .memory_pointer + DK64MemoryMap .fed_string , f"{ stripped_item_name } " )
96- self .n64_client .write_bytestring (self .memory_pointer + DK64MemoryMap .fed_subtitle , f"From { stripped_player_name } " )
106+ self .send_message (item_name , from_player , "from" )
97107 if item_ids .get (item_id ):
98108 if item_ids [item_id ].get ("flag_id" , None ) != None :
99109 self .setFlag (item_ids [item_id ].get ("flag_id" ))
@@ -112,15 +122,6 @@ async def writeFedData(self, fed_item):
112122 break
113123 self .n64_client .write_u8 (self .memory_pointer + 0x7 , fed_item )
114124
115- def check_safe_gameplay (self ):
116- current_gamemode = self .n64_client .read_u8 (DK64MemoryMap .CurrentGamemode )
117- next_gamemode = self .n64_client .read_u8 (DK64MemoryMap .NextGamemode )
118- return current_gamemode in [6 , 0xD ] and next_gamemode in [6 , 0xD ]
119-
120- def safe_to_send (self ):
121- countdown_value = self .n64_client .read_u8 (self .memory_pointer + DK64MemoryMap .safety_text_timer )
122- return countdown_value == 0
123-
124125 def _getShopStatus (self , p_type : int , p_value : int , p_kong : int ) -> bool :
125126 if p_type == 0xFFFF :
126127 return False
@@ -370,10 +371,7 @@ async def main_tick(self, item_get_cb, win_cb):
370371 # Strip out special characters from item name
371372 item_name = item [0 ]
372373 sender = item [1 ]
373- stripped_item_name = "" .join (e for e in item_name if str (e ).isalnum () or str (e ) == " " )
374- stripped_player_name = "" .join (e for e in sender if str (e ).isalnum () or str (e ) == " " )
375- self .n64_client .write_bytestring (self .memory_pointer + DK64MemoryMap .fed_string , f"{ stripped_item_name } " )
376- self .n64_client .write_bytestring (self .memory_pointer + DK64MemoryMap .fed_subtitle , f"To { stripped_player_name } " )
374+ self .send_message (item_name , sender , "to" )
377375 self .sent_checks .remove (item )
378376
379377
@@ -524,7 +522,6 @@ def on_item_get(dk64_checks):
524522 if not self .client .recvd_checks :
525523 await self .sync ()
526524
527- # await self.client.wait_and_init_tracker()
528525 await asyncio .sleep (1.0 )
529526 while True :
530527 await self .client .validate_client_connection ()
0 commit comments