Skip to content

Commit cd67be9

Browse files
authored
Merge pull request ArchipelagoMW#2 from YourAverageLink/more-invalid-states
Defer receiving items on the title screen or while sleeping
2 parents 3f6e354 + 7ba90b0 commit cd67be9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

worlds/ss/Constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# This is the address that holds the player's file name.
2020
FILE_NAME_ADDR = 0x80955D38 # ARRAY[16]
2121

22+
# A bit at this address is set if on the title screen
23+
GLOBAL_TITLE_LOADER_ADDR = 0x80575780
24+
2225
AP_VISITED_STAGE_NAMES_KEY_FORMAT = "ss_visited_stages_%i"
2326

2427
LINK_INVALID_STATES = [
@@ -27,6 +30,8 @@
2730
b'\x5A\x32\x8C', # Door
2831
b'\x5A\x12\xA8', # Diving
2932
b'\xB4\xF4\x50', # Bird picking up link
33+
b'\x5A\x31\xAC', # Sleeping
34+
b'\x5A\x33\x6C', # Waking up
3035
]
3136

3237
# Valid addresses for storyflags (ending in zero - final bit is added to this address)

worlds/ss/SSClient.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ async def _give_item(ctx: SSContext, item_name: str) -> bool:
307307
:param item_name: Name of the item to give.
308308
:return: Whether the item was successfully given.
309309
"""
310-
if not (check_link_state_for_giveitem() and check_alive()):
310+
if not (check_link_state_for_giveitem() and check_alive() and not check_on_title_screen()):
311311
return False
312312

313313
item_id = ITEM_TABLE[item_name].item_id # In game item ID
@@ -331,7 +331,7 @@ async def give_items(ctx: SSContext) -> None:
331331
332332
:param ctx: The SS client context.
333333
"""
334-
if check_link_state_for_giveitem() and check_alive():
334+
if check_link_state_for_giveitem() and check_alive() and not check_on_title_screen():
335335
# Read the expected index of the player, which is the index of the latest item they've received.
336336
expected_idx = dme_read_short(EXPECTED_INDEX_ADDR)
337337

@@ -460,15 +460,23 @@ def check_ingame() -> bool:
460460
461461
:return: `True` if the player is in-game, otherwise `False`.
462462
"""
463-
return dolphin_memory_engine.read_bytes(CURR_STATE_ADDR, 3) != 0x0
463+
return int.from_bytes(dolphin_memory_engine.read_bytes(CURR_STATE_ADDR, 3)) != 0x0
464+
465+
def check_on_title_screen() -> bool:
466+
"""
467+
Check if the player is on the Title Screen.
468+
469+
:return: `True` if the player is on the title screen, otherwise `False`.
470+
"""
471+
return int.from_bytes(dolphin_memory_engine.read_bytes(GLOBAL_TITLE_LOADER_ADDR, 1)) != 0x0
464472

465473
def check_link_state_for_giveitem() -> bool:
466474
"""
467475
Returns a bool determining whether Link is in a valid or invalid state to receive items.
468476
469477
:return: True if Link is in a valid state, False if Link is in an invalid state
470478
"""
471-
linkstate = dolphin_memory_engine.read_bytes(CURR_STATE_ADDR, 4) != 0x0
479+
linkstate = dolphin_memory_engine.read_bytes(CURR_STATE_ADDR, 3)
472480
if linkstate in LINK_INVALID_STATES:
473481
return False
474482
else:

0 commit comments

Comments
 (0)