Bring public main's bug capture on F8 and its removal of the Steam co-op into the 0.10.0 line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/architecture.md
#	launcher/steamlib.py
#	launcher/ui/app.py
#	runtime/boot.c
#	runtime/cfg.c
#	runtime/flight.c
#	runtime/flight.h
#	runtime/gfx_present.c
#	tests/launcher_test.py
This commit is contained in:
chrg6
2026-11-13 09:52:43 -05:00
46 changed files with 1720 additions and 4147 deletions

View File

@@ -1,130 +0,0 @@
"""A second co-op player without a second game, for tests on one PC (docs/coop.md, "Checks").
It speaks the stand-in for Steam (runtime/coop_local.c: datagrams between UDP ports on 127.0.0.1) and the room's
messages (runtime/coop.c, runtime/coop_game.c) to a game started with NX2NAVI_COOP_LOCAL=<host port> and
NX2NAVI_COOP_LOCAL_MAKE=1:
python tests/coop_peer.py --host 27601 [--port 27602] [--seconds 120] [--flags HASH[,HASH...]]
It joins the game's room, says HELLO, and once the game's Link is in the world stands two metres beside him (so the
game shows its name there), says a chat line, asks for the game's shared progress and, with --flags, sends those flags
(hex hashes of on/off flags) as set. It prints what the game sends and ends with "peer: ok" when it was let in, saw
the game's Link in the world and got its progress; python's exit code says the same. Standard library only.
"""
import argparse
import socket
import struct
import sys
import time
L_JOIN, L_MEMBERS, L_DATA, L_LEAVE = 1, 2, 3, 4
K_HELLO, K_WELCOME, K_REFUSED, K_ROSTER, K_POSE, K_CHAT = 1, 2, 3, 4, 5, 6
K_FLAGS, K_ASK = 16, 17
PROTOCOL, GAME_BUILD = 1, 0xE0F3CCFA
def pose_bytes(number, pos, scene):
s = scene.encode()
return struct.pack('<I3f3ffBB', number, *pos, 0.0, 0.0, 0.0, 0.0, 0, len(s)) + s
def main():
ap = argparse.ArgumentParser()
ap.add_argument('--host', type=int, required=True, help="the game's NX2NAVI_COOP_LOCAL port")
ap.add_argument('--port', type=int, default=27602)
ap.add_argument('--seconds', type=float, default=120)
ap.add_argument('--flags', default='', help='hex hashes of on/off flags to send as set, comma separated')
a = ap.parse_args()
flags = [int(h, 16) for h in a.flags.split(',') if h]
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('127.0.0.1', a.port))
sock.settimeout(0.02)
host = ('127.0.0.1', a.host)
def send(kind, body=b''):
sock.sendto(bytes([L_DATA, kind]) + body, host)
start = time.monotonic()
in_lobby = welcomed = False
last_join = last_hello = last_pose = last_ask = 0.0
number = 0
host_pose = None # (scene, x, y, z) as the game last said
schema = None
got_pairs = 0
chatted = flags_sent = False
roster = 0
while time.monotonic() - start < a.seconds:
now = time.monotonic()
if now - last_join >= 1.0:
sock.sendto(bytes([L_JOIN]), host)
last_join = now
if in_lobby and not welcomed and now - last_hello >= 1.0:
send(K_HELLO, struct.pack('<HI', PROTOCOL, GAME_BUILD))
last_hello = now
if welcomed and now - last_pose >= 0.05:
number += 1
if host_pose and host_pose[0]:
send(K_POSE, pose_bytes(number, (host_pose[1] + 2.0, host_pose[2], host_pose[3] + 2.0), host_pose[0]))
else:
send(K_POSE, pose_bytes(number, (0.0, 0.0, 0.0), ''))
last_pose = now
if welcomed and host_pose and host_pose[0] and not chatted:
send(K_CHAT, 'hello from the test peer'.encode())
chatted = True
print('peer: sent a chat line')
if welcomed and schema is not None and now - last_ask >= 5.0:
send(K_ASK, struct.pack('<I', schema))
last_ask = now
if welcomed and schema is not None and flags and not flags_sent:
send(K_FLAGS, struct.pack('<I', schema) + b''.join(struct.pack('<II', h, 1) for h in flags))
flags_sent = True
print(f'peer: sent {len(flags)} flags as set')
try:
d, who = sock.recvfrom(2048)
except (socket.timeout, ConnectionResetError): # nothing yet, or the game's port is not open yet
continue
if who != host or not d:
continue
if d[0] == L_MEMBERS:
if not in_lobby:
print(f'peer: in the lobby with {(len(d) - 1) // 8} members')
in_lobby = True
elif d[0] == L_DATA and len(d) >= 2:
kind, b = d[1], d[2:]
if kind == K_WELCOME:
welcomed = True
print('peer: the host let it in')
elif kind == K_REFUSED:
print(f'peer: REFUSED, reason {b[0] if b else "?"}')
return 1
elif kind == K_ROSTER and b:
if b[0] != roster:
roster = b[0]
print(f'peer: the host lists {roster} players: {[struct.unpack_from("<Q", b, 1 + 8 * i)[0] for i in range(roster)]}')
elif kind == K_POSE and len(b) >= 34:
n, x, y, z, vx, vy, vz, yaw, fl, sl = struct.unpack_from('<I3f3ffBB', b)
scene = b[34:34 + sl].decode(errors='replace')
if host_pose is None or host_pose[0] != scene:
print(f'peer: the game\'s Link: {scene or "(not in the world)"} at {x:.1f} {y:.1f} {z:.1f}, yaw {yaw:.2f}')
host_pose = (scene, x, y, z)
elif kind == K_CHAT:
print(f'peer: chat from the game: {b.decode(errors="replace")}')
elif kind == K_FLAGS and len(b) >= 4:
if schema is None:
schema = struct.unpack_from('<I', b)[0]
print('peer: the game shares progress')
got_pairs += (len(b) - 4) // 8
elif kind == K_ASK and len(b) == 4:
if schema is None:
schema = struct.unpack_from('<I', b)[0]
print('peer: the game asked for the room\'s progress')
sock.sendto(bytes([L_LEAVE]), host)
seen = bool(host_pose and host_pose[0])
print(f'peer: welcomed {welcomed}, saw the game\'s Link in the world {seen}, got {got_pairs} values of its progress')
ok = welcomed and seen and got_pairs > 0
print('peer: ok' if ok else 'peer: FAILED')
return 0 if ok else 1
if __name__ == '__main__':
sys.exit(main())

View File

@@ -49,7 +49,7 @@ ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / 'tools'))
from launcher import build, feed, gameini, gamefiles, jobs, locks, net, saves, settings, steamlib, toolchain, updater, versions, winsys # noqa: E402
from launcher import build, feed, gameini, gamefiles, jobs, locks, net, saves, settings, toolchain, updater, versions, winsys # noqa: E402
from launcher.context import Context # noqa: E402
from launcher.paths import Layout # noqa: E402
@@ -5002,156 +5002,6 @@ def have_display():
@unittest.skipUnless(have_display(), 'needs tkinter, numpy and a display')
class SteamLibTest(Tmp):
"""launcher/steamlib.py: Steam's library file for co-op, found in the player's Steam library and put beside the
game. The files here are made up: the bytes a library's exported names leave in it, no code."""
def lib(self, path, old=False, mtime=None):
names = list(steamlib.NEEDS) + [group[-1] for group in steamlib.ONE_OF]
if old: # a library from before the networking messages interface
names = [n for n in names if b'NetworkingMessages' not in n]
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(b'MZ' + bytes(64) + b'\x00'.join(names) + b'\x00')
if mtime:
os.utime(path, (mtime, mtime))
return path
def steam(self):
"""A Steam folder with a second library elsewhere, as libraryfolders.vdf lists it (backslashes doubled)."""
steam = self.tmp / 'Steam'
other = self.tmp / 'Games Drive' / 'SteamLibrary'
(steam / 'steamapps' / 'common').mkdir(parents=True)
(other / 'steamapps' / 'common').mkdir(parents=True)
one = chr(92)
rows = ''.join('\t"%d"\n\t{\n\t\t"path"\t\t"%s"\n\t}\n' % (i, str(p).replace(one, one + one))
for i, p in enumerate((steam, other)))
(steam / 'steamapps' / 'libraryfolders.vdf').write_text('"libraryfolders"\n{\n' + rows + '}\n', encoding='utf-8')
return steam, other
def test_a_library_is_suitable_only_with_every_call_co_op_uses(self):
self.assertTrue(steamlib.suitable(self.lib(self.tmp / 'a' / steamlib.NAME)))
self.assertFalse(steamlib.suitable(self.lib(self.tmp / 'b' / steamlib.NAME, old=True)))
(self.tmp / 'c').mkdir()
(self.tmp / 'c' / steamlib.NAME).write_bytes(b'not a library at all')
self.assertFalse(steamlib.suitable(self.tmp / 'c' / steamlib.NAME))
self.assertFalse(steamlib.suitable(self.tmp / 'missing' / steamlib.NAME))
def test_the_newest_suitable_signed_library_of_any_steam_library_is_found(self):
steam, other = self.steam()
now = time.time()
self.lib(steam / 'steamapps' / 'common' / 'Old Game' / steamlib.NAME, old=True, mtime=now)
mid = self.lib(steam / 'steamapps' / 'common' / 'Mid Game' / 'bin' / steamlib.NAME, mtime=now - 5000)
new = self.lib(other / 'steamapps' / 'common' / 'Unity Game' / 'Game_Data' / 'Plugins' / 'x86_64' / steamlib.NAME,
mtime=now - 100)
unsigned = self.lib(other / 'steamapps' / 'common' / 'Replaced' / steamlib.NAME, mtime=now - 10)
self.lib(other / 'steamapps' / 'common' / 'Deep' / 'a' / 'b' / 'c' / 'd' / 'e' / 'f' / steamlib.NAME, mtime=now)
self.assertEqual([p.parent.name for p in steamlib.libraries(steam)], ['Steam', 'SteamLibrary'])
self.assertEqual(steamlib.find(steam, lambda p: Path(p) != unsigned), new) # not the old, unsigned or too deep one
self.assertEqual(steamlib.find(steam, lambda p: Path(p) == mid), mid)
self.assertIsNone(steamlib.find(steam, lambda p: False))
self.assertIsNone(steamlib.find(self.tmp / 'no steam here', lambda p: True))
def test_the_library_is_put_beside_the_game_once(self):
steam, other = self.steam()
src = self.lib(other / 'steamapps' / 'common' / 'Some Game' / steamlib.NAME)
game = self.tmp / 'game'
game.mkdir()
lines = []
self.assertEqual(steamlib.ensure(game, None, steam, lines.append, lambda p: True), 'copied')
self.assertEqual((game / steamlib.NAME).read_bytes(), src.read_bytes())
self.assertIn('Some Game', lines[-1])
self.assertEqual(steamlib.ensure(game, None, self.tmp / 'gone', lines.append, lambda p: False), 'there')
# a file beside the game that is not a library co-op can use is replaced
(game / steamlib.NAME).write_bytes(b'MZ old')
self.assertEqual(steamlib.ensure(game, None, steam, lines.append, lambda p: True), 'copied')
self.assertTrue(steamlib.suitable(game / steamlib.NAME))
def test_a_library_the_release_ships_comes_first_and_none_is_said_once(self):
steam, other = self.steam()
kit_bin = self.tmp / 'kit' / 'bin'
shipped = self.lib(kit_bin / steamlib.NAME)
shipped.write_bytes(shipped.read_bytes() + b'shipped')
self.lib(other / 'steamapps' / 'common' / 'Some Game' / steamlib.NAME)
game = self.tmp / 'game'
game.mkdir()
self.assertEqual(steamlib.ensure(game, kit_bin, steam, lambda line: None, lambda p: True), 'copied')
self.assertTrue((game / steamlib.NAME).read_bytes().endswith(b'shipped'))
# nothing suitable anywhere: said in the log once, and not searched again by this process
empty = self.tmp / 'empty game'
empty.mkdir()
lines = []
nothing = self.tmp / 'Steam without games'
(nothing / 'steamapps' / 'common').mkdir(parents=True)
self.assertEqual(steamlib.ensure(empty, None, nothing, lines.append, lambda p: True), 'none')
self.assertEqual(steamlib.ensure(empty, None, steam, lines.append, lambda p: True), 'none')
self.assertEqual(len(lines), 1)
self.assertFalse((empty / steamlib.NAME).exists())
def test_the_library_is_wanted_only_with_co_op_on(self):
"""As runtime/cfg.c reads co-op: NX2NAVI_COOP_STEAM first, else the game's nx2navi.ini, off by default; the
old switch, coop, turns nothing on."""
game = self.tmp / 'game'
game.mkdir()
with mock.patch.dict(os.environ):
os.environ.pop('NX2NAVI_COOP_STEAM', None)
self.assertFalse(steamlib.wanted(game)) # no settings file: the default, off
(game / 'nx2navi.ini').write_text('[coop]\ncoop_steam = 0\n', encoding='utf-8')
self.assertFalse(steamlib.wanted(game))
(game / 'nx2navi.ini').write_text('[coop]\ncoop = 1\n', encoding='utf-8')
self.assertFalse(steamlib.wanted(game)) # the old switch turns nothing on
(game / 'nx2navi.ini').write_text('[coop]\ncoop_steam = 1\ncoop_steam =\n', encoding='utf-8')
self.assertTrue(steamlib.wanted(game)) # an empty line leaves the earlier value
os.environ['NX2NAVI_COOP_STEAM'] = '0'
self.assertFalse(steamlib.wanted(game)) # the environment wins, as in the game
os.environ['NX2NAVI_COOP_STEAM'] = '1'
self.assertTrue(steamlib.wanted(self.tmp / 'no game'))
def test_play_waits_for_the_library_only_with_co_op_on_and_not_on_the_windows_thread(self):
game = self.tmp / 'game'
game.mkdir()
(game / 'ocarina.exe').write_bytes(b'MZ')
App, a = mock_app(self, game)
a.game_proc, a.game_starting = None, False
a.mods_before_play.return_value = []
a.start_game = lambda gd, exe: App.start_game(a, gd, exe)
a.launch = lambda exe: App.launch(a, exe)
searched = []
done = threading.Event()
def ensure(*args, **kwargs):
searched.append(threading.current_thread())
done.set()
return 'none'
with mock.patch.dict(os.environ), mock.patch('launcher.ui.app.steamlib.ensure', side_effect=ensure), \
mock.patch('launcher.ui.app.winsys.start_game') as start, \
mock.patch('launcher.ui.app.saves.game_running', return_value=False):
os.environ.pop('NX2NAVI_COOP_STEAM', None)
App.play(a) # co-op off: no search, the game starts
self.assertEqual(searched, [])
start.assert_called_once_with(game / 'ocarina.exe')
a.game_proc = None
start.reset_mock()
a.root.after.reset_mock()
gameini.put(game, 'coop', 'coop_steam', '1')
App.play(a) # co-op on: the search runs on its own thread
self.assertTrue(done.wait(10))
self.assertNotEqual(searched, [threading.current_thread()])
self.assertTrue(a.game_starting)
App.play(a) # a second Play while it waits does nothing
self.assertEqual(len(searched), 1)
for _ in range(1000): # the thread hands the start to the window's
if a.root.after.call_args_list:
break
time.sleep(0.01)
start.assert_not_called()
delay, then = a.root.after.call_args_list[0][0]
self.assertEqual(delay, 0)
then()
start.assert_called_once_with(game / 'ocarina.exe')
self.assertFalse(a.game_starting)
self.assertEqual(a.message, '')
class SteamTest(Tmp):
"""launcher/steam.py on made-up Steam files: the binary shortcuts file read and written back unchanged, our
shortcut added beside another and updated in place, its id as Steam computes it, the accounts that signed in."""

View File

@@ -65,7 +65,6 @@ int romfs_owns(const char *path) { (void)path; return 0; }
int mem_probing(void) { return 0; } // write_file asks before each write: no probe, no lazy heap here
void mem_kernel_access(uint64_t a, uint64_t n) { (void)a, (void)n; }
void fs_trace(const char *what, const char *path) { (void)what, (void)path; }
void coop_game_rom_open(const char *path) { (void)path; } // co-op watches for the title screen's start: not here
int main(int argc, char **argv) {
if (argc < 3) return 2;