mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 06:09:58 -04:00
Have the launcher put Steam's library file beside the game, so no player fetches it for co-op.
Co-op loads steam_api64.dll from beside ocarina.exe, and the repository may not hold that file. Before Play and before a start from the Steam shortcut, when the file is not there, launcher/steamlib.py now copies one: one a release ships in its bin folder if it has one, else the newest one in the games of the player's own Steam libraries that Valve signed (WinVerifyTrust and the signer's name) and that has every call runtime/steam.c uses. Nothing is downloaded, the search takes a second or two once, and with no Steam or no suitable file the game starts as before and the Co-op tab says what is missing. The tab's two texts about the file say so in the four languages. Checked: four new tests on made-up library folders (too old, unsigned, too deep, a second library, a shipped file first, none said once) and the launcher's 190 tests pass; on this PC the search found 40 files in 1.2 s, 25 suitable, and copied a Valve-signed one; that file's library version, an older one than the game was run with, signs in as app 480 and makes a lobby in a program without the game. Not run: Play in the launcher itself with this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -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, net, saves, settings, toolchain, updater, versions, winsys # noqa: E402
|
||||
from launcher import build, feed, gameini, gamefiles, jobs, net, saves, settings, steamlib, toolchain, updater, versions, winsys # noqa: E402
|
||||
from launcher.context import Context # noqa: E402
|
||||
from launcher.paths import Layout # noqa: E402
|
||||
|
||||
@@ -4502,6 +4502,92 @@ 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())
|
||||
|
||||
|
||||
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."""
|
||||
|
||||
Reference in New Issue
Block a user