Add the game to Steam from Customize Launcher, with Navi as its icon and the title screen's moonlit field and logo as its pictures, made from the player's own game.

The new row, Add to Steam (Windows), puts a non-Steam shortcut named "The Legend of Zelda Ocarina of Time" into the shortcuts.vdf of every Steam account that signed in on the PC (launcher/steam.py): the binary key-value file is read and written back as it was, with ours added or updated in place, and the file from before the first change kept beside it. Steam reads that file only at its start and writes it back when it closes, so a running Steam is asked to close (-shutdown) and started again after.

The pictures come from the player's game when the row is selected (launcher/gameart.py), as the launcher's fonts and sounds do: Navi from the HUD's icon and its glow, the logo with the Master Sword and the Hylian Shield from the title screen's texture archive (decoded with runtime/tex_astc.c, built into a library with the toolchain's clang), and a frame 12 seconds into the first title movie, the field under the full moon, decoded from its AV1 with the toolchain's dav1d.exe, as the background, the cover and the wide tile. They go into config/grid named by the shortcut's id, CRC-32 of Exe and AppName with the top bit set, which matches the id Steam gave an existing shortcut on the test PC.

Steam starts the launcher's pythonw.exe on data/steam_play.pyw, which runs the launcher of app/current.txt with the new --play: the game starts from its folder with its console hidden, as Play starts it, and the process waits for it and for the copies its own Restart starts, so Steam counts the game as running while it is. ocarina.exe is a console program, so starting it directly would open a console window beside the game, and NX2navi.exe ends six seconds after it started the launcher. Started that way on an RX 7900 XT PC, the game ran, the Python process stayed until the game was closed and ended with code 0. Tested against copies of that PC's Steam files; the real Steam library is not changed until the player selects the row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epicmeme546
2026-11-10 13:49:06 -05:00
parent da0d0be700
commit a7b8810d37
6 changed files with 860 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ Run: python tests/launcher_test.py (Python 3.14 for the zstd tests; the window
a source checkout's build/xlate/), the prompts step with a stand-in prompt tool, the object cache of the compile
step with the system's C compiler, and its windres call under folders with spaces (a script in windres's place)
- jobs: an install driven by a fake make_game.py, with and without the prompts row
- Add to Steam: the binary shortcuts file read and written back unchanged, a shortcut added and updated in place
- the look: the colour schemes, the background picture's fitting and kept copy, the sound effects (low by default,
only the game's own select and back sounds, decoded from a made-up .bwav)
- the window: --selftest draws every screen (skipped without a display)
@@ -2839,6 +2840,60 @@ def have_display():
@unittest.skipUnless(have_display(), 'needs tkinter, numpy and a display')
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."""
def other(self):
from launcher import steam
exe = '"C:\\Games\\Other\\other.exe"'
entry = [[steam.T_INT, 'appid', struct.pack('<I', steam.appid(exe, 'Other'))], [steam.T_STR, 'AppName', 'Other'],
[steam.T_STR, 'Exe', exe], [steam.T_STR, 'StartDir', '"C:\\Games\\Other\\"'],
[steam.T_STR, 'icon', ''], [steam.T_INT, 'LastPlayTime', struct.pack('<I', 1234)],
[steam.T_STR, 'sortas', ''], [steam.T_MAP, 'tags', [[steam.T_STR, '0', 'Favorite']]]]
return steam.vdf_dump([[steam.T_MAP, 'shortcuts', [[steam.T_MAP, '0', entry]]]])
def test_round_trip_add_and_update(self):
from launcher import steam
b = self.other()
self.assertEqual(b[-4:], b'\x08\x08\x08\x08') # tags, the shortcut, shortcuts, the file
self.assertEqual(steam.vdf_dump(steam.vdf_load(b)), b)
self.assertFalse(steam.has_shortcut(b))
new, sid = steam.add_shortcut(b, '"C:\\NX2navi\\python\\pythonw.exe"', '"C:\\NX2navi"',
'"C:\\NX2navi\\data\\steam_play.pyw"', 'C:\\grid\\x_icon.png')
self.assertEqual(sid, steam.appid('"C:\\NX2navi\\python\\pythonw.exe"', steam.NAME))
self.assertTrue(sid & 0x80000000)
self.assertTrue(new.startswith(b[:-2])) # the other shortcut stays byte for byte
self.assertTrue(steam.has_shortcut(new))
items = steam.vdf_load(new)[0][2]
self.assertEqual([k for _, k, _ in items], ['0', '1'])
ours = {k: v for _, k, v in items[1][2]}
self.assertEqual(ours['AppName'], 'The Legend of Zelda Ocarina of Time')
self.assertEqual(struct.unpack('<I', ours['appid'])[0], sid)
self.assertEqual(ours['LaunchOptions'], '"C:\\NX2navi\\data\\steam_play.pyw"')
self.assertEqual(ours['AllowOverlay'], struct.pack('<I', 1))
again, _ = steam.add_shortcut(new, '"D:\\NX2navi\\python\\pythonw.exe"', '"D:\\NX2navi"', '', 'x')
items = steam.vdf_load(again)[0][2]
self.assertEqual(len(items), 2) # moved launcher: the same shortcut, updated
self.assertEqual({k: v for _, k, v in items[1][2]}['StartDir'], '"D:\\NX2navi"')
with self.assertRaises(steam.SteamError):
steam.vdf_load(b[:-5])
def test_new_file_and_accounts(self):
from launcher import steam
new, _ = steam.add_shortcut(b'', '"x.exe"', '"."', '', '')
self.assertTrue(steam.has_shortcut(new))
root = self.tmp / 'Steam'
for a in ('0', '1046310423', '22'):
(root / 'userdata' / a / 'config').mkdir(parents=True)
(root / 'config').mkdir()
(root / 'config' / 'loginusers.vdf').write_text('"users"\n{\n\t"76561199006576151"\n\t{\n\t}\n}\n')
self.assertEqual(steam.accounts(root), [root / 'userdata' / '1046310423' / 'config'])
(root / 'config' / 'loginusers.vdf').unlink()
self.assertEqual(steam.accounts(root), sorted([root / 'userdata' / '1046310423' / 'config',
root / 'userdata' / '22' / 'config']))
class WhilePlayingTest(Tmp):
def test_the_games_restart_does_not_bring_the_launcher_back(self):
try: