Skip to content

Commit 16f238c

Browse files
committed
format
1 parent 5e298e4 commit 16f238c

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
lines changed

DK64Client.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,46 @@ def safe_to_send(self):
110110
countdown_value = self.n64_client.read_u8(memory_location + DK64MemoryMap.safety_text_timer)
111111
return countdown_value == 0
112112

113+
def _getShopStatus(self, p_type: int, p_value: int, p_kong: int) -> bool:
114+
if p_type == 0xFFFF:
115+
return False
116+
if p_value == 0:
117+
return False
118+
if p_kong > 4:
119+
p_kong = 0
120+
kong_base = 0x807FC950 + (p_kong * 0x5E)
121+
if p_type < 5:
122+
val = self.n64_client.read_u8(kong_base + p_type)
123+
if p_type in (1, 3):
124+
# Slam, Ammo Belt
125+
return val >= p_type
126+
else:
127+
return (val & (1 << (p_value - 1))) != 0
128+
else:
129+
return self.readFlag(p_value) != 0
130+
131+
def getCheckStatus(self, check_type, flag_index=None, shop_index=None, level_index=None, kong_index=None) -> bool:
132+
# shop_index: 0 = cranky, 1 = funky, 2 = candy, 3=bfi
133+
# flag_index: as expected
134+
if check_type == "shop":
135+
if shop_index == 3:
136+
header = 0x807FF6E8
137+
else:
138+
header = 0x807FF400 + (shop_index * 0xF0) + (kong_index * 0x30) + (level_index * 6)
139+
purchase_type = self.n64_client.read_u16(header + 0)
140+
purchase_value = self.n64_client.read_u16(header + 2)
141+
purchase_kong = self.n64_client.read_u8(header + 4)
142+
return self._getShopStatus(purchase_type, purchase_value, purchase_kong)
143+
else:
144+
for flut_index in range(0x400):
145+
raw_flag = self.n64_client.read_u16(0x807E2EE0 + (4 * flut_index))
146+
if raw_flag == flag_index:
147+
target_flag = self.n64_client.read_u16(0x807E2EE0 + (4 * flut_index) + 2)
148+
return self.readFlag(target_flag) != 0
149+
elif raw_flag == 0xFFFF:
150+
return self.readFlag(flag_index) != 0
151+
152+
# TODO: We need to modify this function to use getCheckStatus instead of the gameboy logic
113153
async def readChecks(self, cb):
114154
new_checks = []
115155
for check in self.remaining_checks:

worlds/dk64/client/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
value = location_flag_ids[flag]
77
if location_names_to_id.get(value):
88
print(value)
9-
10-
print(len(location_flag_ids))
9+
10+
print(len(location_flag_ids))

worlds/dk64/client/item_ids.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# AP_ID, Name, Flag Id (Hex int), Fed ID (standard int)
32
item_ids = {
43
14041089: {"name": "No Item", "fed_id": None, "flag_id": 0},

worlds/dk64/client/location_ids.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
location_flag_ids = {
32
1: "Japes Lanky Mad Maze Maul",
43
2: "Japes Tiny Splish-Splash Salvage",
@@ -351,4 +350,3 @@
351350
# 736: "Isles Dirt: Banana Hoard",
352351
# 739: "Isles Dirt: Castle Lobby",
353352
}
354-

worlds/dk64/client/pj64.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import socket
44
import json
5-
from client_options.common import N64Exception
5+
from dk64.client.common import N64Exception
66

77

88
class PJ64Client:
@@ -89,6 +89,28 @@ def read_u8(self, address):
8989
except (ConnectionRefusedError, ConnectionResetError, ConnectionAbortedError):
9090
raise N64Exception("Connection refused or reset")
9191

92+
def read_u16(self, address):
93+
"""
94+
Reads a 16-bit unsigned integer from the specified memory address.
95+
96+
Args:
97+
address (int): The memory address to read from.
98+
99+
Returns:
100+
int: The 16-bit unsigned integer read from the specified address.
101+
102+
Raises:
103+
N64Exception: If the connection is refused, reset, or aborted.
104+
"""
105+
try:
106+
self._connect()
107+
address = hex(address)
108+
self.socket.send(f"read u16 {address} 2".encode())
109+
data = int(self.socket.recv(1024).decode())
110+
return data
111+
except (ConnectionRefusedError, ConnectionResetError, ConnectionAbortedError):
112+
raise N64Exception("Connection refused or reset")
113+
92114
def read_u32(self, address):
93115
"""
94116
Reads a 32-bit unsigned integer from the specified memory address.

0 commit comments

Comments
 (0)