3535CURRENT_INDEX_ADDR = 0
3636
3737# This address contains the current stage / room ID.
38- CURR_STAGE_ID_ADDR = 0x8026644C
38+ CURR_STAGE_ID_ADDR = 0x8025f847
39+
40+ CURR_GAME_STATE = 0x8025df17
3941
4042# This address is used to check/set the player's battery
41- CURR_BATTERY_ADDR = 0x8396558
43+ CURR_BATTERY_ADDR = 0x8038f748
4244
4345GC_GAME_ID_ADDRESS = 0x80000000
4446
4850
4951HAPPY_POINTS_ADDR = 0x8039653C
5052
53+ BASE_ITEM_ADDR = 0x80370000
54+
5155class ChibiRoboJSONToTextParser (JSONtoTextParser ):
5256 def _handle_color (self , node : JSONMessagePart ):
5357 return self ._handle_text (node ) # No colors for the in-game text
@@ -71,6 +75,16 @@ def _cmd_debug(self) -> None:
7175 # logger.info(f"{self.ctx.location_names["Chibi Robo"]}")
7276 return
7377
78+ def _cmd_equip_blaster (self ) -> None :
79+ """
80+ Equip Blaster
81+ """
82+ if isinstance (self .ctx , ChibiRoboContext ):
83+ dolphin_memory_engine .write_bytes (0x8038f6c2 , bytes (2 ))
84+ dolphin_memory_engine .write_bytes (0x8038f6c4 , bytes (0 ))
85+ dolphin_memory_engine .write_bytes (0x8038f6c6 , bytes (2 ))
86+ return
87+
7488 def _cmd_dolphin (self ) -> None :
7589 """
7690 Display the current Dolphin emulator connection status.
@@ -288,8 +302,6 @@ def _give_item(ctx: ChibiRoboContext, item_name: str) -> bool:
288302 :param item_name: Name of the item to give.
289303 :return: Whether the item was successfully given.
290304 """
291- global CURR_STAGE_ID_ADDR
292- global EXPECTED_INDEX_ADDR
293305
294306 if not check_ingame () or dolphin_memory_engine .read_bytes (CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0e " :
295307 return False
@@ -368,7 +380,9 @@ def check_ingame() -> bool:
368380 :return: `True` if the player is in-game, otherwise `False`.
369381 """
370382
371- return dolphin_memory_engine .read_bytes (CURR_STAGE_ID_ADDR , 4 ) not in ["" , '\x00 \x00 \x00 \x0e ' , '\x00 \x00 \x00 \x01 ' , '\x00 \x00 \x00 \x02 ' , '\x00 \x00 \x00 \x03 ' , '\x00 \x00 \x00 \x04 ' , '\x00 \x00 \x00 \x05 ' , '\x00 \x00 \x00 \x06 ' ,'\x00 \x00 \x00 \x07 ' ,'\x00 \x00 \x00 \x09 ' ,'\x00 \x00 \x00 \x0a ' ,'\x00 \x00 \x00 \x0b ' ,'\x00 \x00 \x00 \x10 ' ,'\x00 \x00 \x00 \x12 ' ,'\x00 \x00 \x00 \x16 ' ]
383+ # logger.info(dolphin_memory_engine.read_bytes(CURR_GAME_STATE, 1))
384+
385+ return dolphin_memory_engine .read_bytes (CURR_GAME_STATE , 1 ) not in ["" , '\x00 ' , '\x40 ' , '\x07 ' ]
372386
373387async def give_items (ctx : ChibiRoboContext ) -> None :
374388 """
@@ -429,6 +443,13 @@ async def check_locations(ctx: ChibiRoboContext) -> None:
429443 curr_stage_id = stage_hex_to_id ()
430444 ctx .curr_stage_pickup = read_4byte_short (EXPECTED_INDEX_ADDR )
431445
446+ for location , data in LOCATION_TABLE .items ():
447+ checked = False
448+
449+ # logger.info(data.bit)
450+
451+ checked = check_location (ctx , curr_stage_id , location , data )
452+
432453 if ctx .curr_stage_pickup != 65535 :
433454
434455 # Loop through all locations to see if each has been checked.
@@ -472,79 +493,88 @@ def check_location(ctx: ChibiRoboContext, curr_stage_id: int, name: str ,data: C
472493 checked = False
473494 # If the location is in the current stage, check the bitfields for the current stage as well.
474495 if not checked and curr_stage_id == data .stage_id :
475- # logger.info(name)
476- checked = bool ((ctx .curr_stage_pickup >> data .bit ) & 1 )
496+
497+ if data .address :
498+
499+ logger .info (name )
500+
501+ location_addr = hex (BASE_ITEM_ADDR + data .address )
502+
503+ logger .info ( dolphin_memory_engine .read_bytes (int ( location_addr , 16 ), 4 ) )
504+
505+ # checked = bool((ctx.curr_stage_pickup >> data.bit) & 1)
477506
478507 return checked
479508
480509def stage_hex_to_name () -> str :
481- global CURR_STAGE_ID_ADDR
510+ stage_value = dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 1 )
482511
483- if dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0e " :
512+ if stage_value == b"\x0e " :
484513 return "Menu"
485- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x01 " :
514+ elif stage_value == b"\x01 " :
486515 return "Kitchen"
487- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x02 " :
516+ elif stage_value == b"\x02 " :
488517 return "Foyer"
489- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x03 " :
518+ elif stage_value == b"\x03 " :
490519 return "Basement"
491- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x04 " :
520+ elif stage_value == b"\x04 " :
492521 return "Jenny's Room"
493- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x05 " :
522+ elif stage_value == b"\x05 " :
494523 return "Chibi House"
495- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x06 " :
524+ elif stage_value == b"\x06 " :
496525 return "Bedroom"
497- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x07 " :
526+ elif stage_value == b"\x07 " :
498527 return "Living Room"
499- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x09 " :
528+ elif stage_value == b"\x09 " :
500529 return "Backyard"
501- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0a " :
530+ elif stage_value == b"\x0a " :
502531 return "Staff Credits"
503- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0b " :
532+ elif stage_value == b"\x0b " :
504533 return "Drain"
505- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0e " :
534+ elif stage_value == b"\x0e " :
506535 return "Living Room (Birthday)"
507- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x10 " :
536+ elif stage_value == b"\x10 " :
508537 return "UFO"
509- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x12 " :
538+ elif stage_value == b"\x12 " :
510539 return "Bedroom (Past)"
511- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x16 " :
540+ elif stage_value == b"\x16 " :
512541 return "Mother Spider Boss"
513542
514543 return "Could Not Find Room / Stage Name"
515544
516545def stage_hex_to_id () -> int :
517- global CURR_STAGE_ID_ADDR
518546
519- if dolphin_memory_engine .read_bytes (CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0e " :
547+ stage_value = dolphin_memory_engine .read_bytes (CURR_STAGE_ID_ADDR , 1 )
548+
549+ if stage_value == b"\x0e " :
520550 return 0 # 'Menu'
521- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x01 " :
551+ elif stage_value == b"\x01 " :
522552 return 1 # "Kitchen"
523- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x02 " :
553+ elif stage_value == b"\x02 " :
524554 return 2 #"Foyer"
525- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x03 " :
555+ elif stage_value == b"\x03 " :
526556 return 3 #"Basement"
527- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x04 " :
557+ elif stage_value == b"\x04 " :
528558 return 4 #"Jenny's Room"
529- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x05 " :
559+ elif stage_value == b"\x05 " :
530560 return 5 #"Chibi House"
531- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x06 " :
561+ elif stage_value == b"\x06 " :
532562 return 6 #"Bedroom"
533- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x07 " :
563+ elif stage_value == b"\x07 " :
534564 return 7 #"Living Room"
535- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x09 " :
565+ elif stage_value == b"\x09 " :
536566 return 8 #"Backyard"
537- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0a " :
567+ elif stage_value == b"\x0a " :
538568 return 9 #"Staff Credits"
539- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0b " :
569+ elif stage_value == b"\x0b " :
540570 return 10 #"Drain"
541- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x0e " :
571+ elif stage_value == b"\x0e " :
542572 return 11 #"Living Room (Birthday)"
543- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x10 " :
573+ elif stage_value == b"\x10 " :
544574 return 12 #"UFO"
545- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x12 " :
575+ elif stage_value == b"\x12 " :
546576 return 13 #"Bedroom (Past)"
547- elif dolphin_memory_engine . read_bytes ( CURR_STAGE_ID_ADDR , 4 ) == b"\x00 \x00 \x00 \x16 " :
577+ elif stage_value == b"\x16 " :
548578 return 14 #"Mother Spider Boss"
549579
550580 return - 1 #"Could Not Find Room / Stage Name"
@@ -581,6 +611,9 @@ async def check_alive() -> bool:
581611 :return: `True` if the player is alive, otherwise `False`.
582612 """
583613 cur_health = read_short (CURR_BATTERY_ADDR )
614+
615+ logger .info (cur_health )
616+
584617 return cur_health > 0
585618
586619
@@ -628,7 +661,7 @@ async def dolphin_sync_task(ctx: ChibiRoboContext) -> None:
628661 dolphin_memory_engine .hook ()
629662 if dolphin_memory_engine .is_hooked ():
630663
631- if dolphin_memory_engine .read_bytes (0x80000000 , 6 ) != b"GGTP01 " :
664+ if dolphin_memory_engine .read_bytes (0x80000000 , 6 ) != b"GGTE01 " :
632665 ctx .dolphin_status = CONNECTION_REFUSED_GAME_STATUS
633666 dolphin_memory_engine .un_hook ()
634667 sleep_time = 5
0 commit comments