66
77if __name__ == "__main__" :
88 Utils .init_logging ("DK64Context" , exception_logger = "Client" )
9-
9+ import json
1010import asyncio
1111import colorama
1212import time
@@ -124,7 +124,6 @@ def check_safe_gameplay(self):
124124 def safe_to_send (self ):
125125 countdown_value = self .n64_client .read_u8 (self .memory_pointer + DK64MemoryMap .safety_text_timer )
126126 return countdown_value == 0
127-
128127 def _getShopStatus (self , p_type : int , p_value : int , p_kong : int ) -> bool :
129128 if p_type == 0xFFFF :
130129 return False
@@ -203,10 +202,16 @@ def getCheckStatus(self, check_type, flag_index=None, shop_index=None, level_ind
203202 has_camera = self .readFlag (0x2FD ) != 0
204203 has_shockwave = self .readFlag (0x179 ) != 0
205204 return has_camera and has_shockwave
206- return self .readFlag (target_flag ) != 0
205+ return self .bulk_read_dict . get (target_flag ) != 0
207206 else :
208- return self .readFlag (flag_index ) != 0
209-
207+ return self .bulk_read_dict .get (flag_index ) != 0
208+
209+ def bulk_lookup (self , flag_index ):
210+ if flag_index in self .flag_lookup :
211+ target_flag = self .flag_lookup [flag_index ]
212+ self .BulkreadFlag (target_flag )
213+ else :
214+ self .BulkreadFlag (flag_index )
210215 async def readChecks (self , cb ):
211216 """Run checks in parallel using asyncio with optimized processing."""
212217 new_checks = []
@@ -218,7 +223,35 @@ async def readChecks(self, cb):
218223 }
219224 shop_map = {"Cranky" : 0 , "Funky" : 1 , "Candy" : 2 }
220225 kong_map = {"Donkey" : 0 , "Diddy" : 1 , "Lanky" : 2 , "Tiny" : 3 , "Chunky" : 4 }
226+ self .bulk_read_dict = {}
227+ for id in self .remaining_checks [:]: # Iterate over a copy to avoid modification issues
228+ if self .flag_lookup is None :
229+ self ._build_flag_lookup ()
230+ name = check_id_to_name .get (id )
231+ if not name :
232+ continue
221233
234+ # Check location_name_to_flag first
235+ check = location_name_to_flag .get (name )
236+ if check :
237+ self .bulk_lookup (check )
238+
239+ # Check item_ids for flag_id
240+ check = item_ids .get (id )
241+ if check :
242+ flag_id = check .get ("flag_id" )
243+ if flag_id :
244+ self .bulk_lookup (flag_id )
245+ def byte_shift (index , val ):
246+ shift = index & 7
247+ return (val >> shift ) & 1
248+ dict_data = self .n64_client .read_dict (self .bulk_read_dict )
249+ # Json loads the dict_data
250+ dict_data = json .loads (dict_data )
251+ self .bulk_read_dict = {}
252+ # For each item in the dict, the key is the index the value is the val for byte_shift. Keep the key the same but set the value to the result of byte_shift
253+ for key , val in dict_data .items ():
254+ self .bulk_read_dict [int (key )] = byte_shift (int (key ), int (val [0 ]))
222255 for id in self .remaining_checks [:]: # Iterate over a copy to avoid modification issues
223256 name = check_id_to_name .get (id )
224257 if not name :
@@ -227,6 +260,7 @@ async def readChecks(self, cb):
227260 # Check location_name_to_flag first
228261 check = location_name_to_flag .get (name )
229262 if check and self .getCheckStatus ("location" , check ):
263+ print (name )
230264 new_checks .append (id )
231265 remove_checks .add (id )
232266 continue
@@ -236,6 +270,7 @@ async def readChecks(self, cb):
236270 if check :
237271 flag_id = check .get ("flag_id" )
238272 if flag_id and self .getCheckStatus ("location" , flag_id ):
273+ print (name )
239274 new_checks .append (id )
240275 remove_checks .add (id )
241276 continue
@@ -294,6 +329,11 @@ def readFlag(self, index: int) -> int:
294329 offset = DK64MemoryMap .EEPROM + byte_index
295330 val = self .n64_client .read_u8 (offset )
296331 return (val >> shift ) & 1
332+ bulk_read_dict = {}
333+ def BulkreadFlag (self , index : int ) -> int :
334+ byte_index = index >> 3
335+ offset = DK64MemoryMap .EEPROM + byte_index
336+ self .bulk_read_dict [index ] = offset
297337
298338 async def wait_for_game_ready (self ):
299339 logger .info ("Waiting on game to be in valid state..." )
@@ -492,7 +532,7 @@ def on_item_get(dk64_checks):
492532 await self .client .validate_client_connection ()
493533 status = self .client .check_safe_gameplay ()
494534 if status == False :
495- await asyncio .sleep (5 )
535+ await asyncio .sleep (0. 5 )
496536 continue
497537 await self .client .main_tick (on_item_get , victory )
498538 await asyncio .sleep (1 )
0 commit comments