Skip to content

Commit 15b02a4

Browse files
committed
Fix submodule pointer
1 parent 03881cc commit 15b02a4

File tree

4 files changed

+103
-16
lines changed

4 files changed

+103
-16
lines changed

worlds/dk64/DK64Client.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
if __name__ == "__main__":
88
Utils.init_logging("DK64Context", exception_logger="Client")
9-
9+
import json
1010
import asyncio
1111
import colorama
1212
import 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)

worlds/dk64/DK64R

Submodule DK64R updated from ac3f801 to 72b2733

worlds/dk64/client/adapter.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,57 @@ function startServer() {
5050
c.write("Usage: read u8/u16/u32 0xADDRESS SIZE");
5151
}
5252
}
53-
53+
else if (message.startsWith("dict")) {
54+
// Remove "dict " from the beginning
55+
var dict = message.substring(5);
56+
try {
57+
dict = JSON.parse(dict);
58+
} catch (e) {
59+
console.log(e)
60+
c.write("Invalid JSON format for dictionary");
61+
return;
62+
}
63+
// eg dict {"name": {"type": "u8", "adr": 0x1234, "size": 4}}
64+
var result = {};
65+
for (var key in dict) {
66+
var item = dict[key];
67+
// If the item is not a dict, assume we just got the address and convert it to a dict
68+
if (typeof item !== "object") {
69+
item = {"adr": item};
70+
}
71+
// If type is not defined default to u8
72+
if (!item.type) {
73+
item.type = "u8";
74+
}
75+
if (!item.size) {
76+
item.size = 1;
77+
}
78+
if (item.type === "u8") {
79+
var values = [];
80+
for (var i = 0; i < item.size; i++) {
81+
values.push(mem.u8[item.adr + i]);
82+
}
83+
result[key] = values;
84+
} else if (item.type === "u16") {
85+
var values = [];
86+
for (var i = 0; i < item.size; i += 2) {
87+
values.push(mem.u16[item.adr + i]);
88+
}
89+
result[key] = values;
90+
} else if (item.type === "u32") {
91+
var values = [];
92+
for (var i = 0; i < item.size; i += 4) {
93+
values.push(mem.u32[item.adr + i]);
94+
}
95+
result[key] = values;
96+
} else {
97+
c.write("Invalid type, use: u8, u16, u32");
98+
return;
99+
}
100+
}
101+
c.write(JSON.stringify(result));
102+
return;
103+
}
54104
else if (message.startsWith("write")) {
55105
var parts = message.split(" ");
56106
var type = parts[1];

worlds/dk64/client/pj64.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def _send_command(self, command):
154154
"""Sends a command to the emulator and retrieves the response."""
155155
try:
156156
self._connect()
157-
self.socket.send(command.encode())
158-
response = self.socket.recv(1024).decode()
157+
self.socket.sendall(command.encode())
158+
response = self.socket.recv(4096).decode()
159159
if not response:
160160
raise PJ64Exception("No data received from the server")
161161
return response
@@ -182,12 +182,9 @@ def read_u32(self, address):
182182
"""Reads a 32-bit unsigned integer from memory."""
183183
return self._read_memory(address, 4)
184184

185-
def read_u8_block(self, address, size):
186-
"""Reads an unsigned integer of the given size from memory."""
187-
resp = self._send_command(f"read u8 {hex(address)} {size}")
188-
# Split by commas and convert to integers
189-
return [x for x in resp.split(",")]
190-
185+
def read_dict(self, dict):
186+
"""Reads a dictionary of memory addresses and returns the values."""
187+
return self._send_command(f"dict {json.dumps(dict, separators=(',', ':'))}")
191188
def _write_memory(self, command, address, data):
192189
"""Writes data to memory and returns the emulator response."""
193190
return self._send_command(f"{command} {hex(address)} [{data}]")

0 commit comments

Comments
 (0)