mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5b0db1313 | ||
|
|
45aae2ded8 | ||
|
|
a51441b365 | ||
|
|
0b1b4f4d86 | ||
|
|
b609b83c83 | ||
|
|
22afb0b797 |
No files matched your search
@@ -95,6 +95,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
|
||||
- Battle.net is by [@kayakyakr](https://github.com/kayakyakr). It runs Blizzard's own client in Proton (downloaded from Blizzard, not included) and shows key art from the [Battle.net Shop](https://shop.battle.net). Without Steam, its games see the pad as an Xbox 360 controller via `PROTON_SPOOF_STEAMINPUT_VIDPID` in [Proton](https://github.com/ValveSoftware/wine)'s `dlls/winebus.sys`.
|
||||
- The EA store follows the EA app's protocols as documented by [ArmchairDevelopers](https://github.com/ArmchairDevelopers)' [Maxima](https://github.com/ArmchairDevelopers/Maxima) (GPL-3.0): sign-in, the GraphQL queries (included verbatim, since EA matches them by hash), build archives, online activation licences and the LSX game endpoint. The code is DroidDeck's own.
|
||||
- Battle.net installs drive Blizzard's Agent the way [@barncastle](https://github.com/barncastle)'s [Battle.Net-Installer](https://github.com/barncastle/Battle.Net-Installer) does, with requests from [wowdev.wiki](https://wowdev.wiki/Agent). Read without taking code: [@mubaraknumann](https://github.com/mubaraknumann)'s [unifideck](https://github.com/mubaraknumann/unifideck), [@djmittens](https://github.com/djmittens)'s [neo-mittens](https://github.com/djmittens/neo-mittens) `bnetswitch`, [@BCD1210](https://github.com/BCD1210)'s [soju](https://github.com/BCD1210/soju) and [Lutris](https://github.com/lutris/lutris)'s `product.db` reader.
|
||||
- The Rockstar launcher service looks for launcher pipe names in the executables beside the game, since [CitizenFX](https://github.com/citizenfx/fivem)'s `ros-patches-five` shows GTA V opening `GTAVLauncher_Pipe` and [@pingod](https://github.com/pingod)'s [rdr2-linux-launcher](https://github.com/pingod/rdr2-linux-launcher) notes that Rockstar's protected executables resolve such strings only at run time. Read without taking code.
|
||||
- World of Warcraft addon imports replace an addon's folder from a temporary copy, as [WowUp](https://github.com/WowUp/WowUp) does, and read flavour folders the way [WoWDeck](https://github.com/sigboe/wowdeck) does. No code from either is used.
|
||||
- The World of Warcraft addon Download window searches [WoWInterface](https://www.wowinterface.com) through its MMOUI API. [CurseForge](https://www.curseforge.com/wow) opens in the user's browser, with no API and no key.
|
||||
- Xbox games load [@domsvoboda](https://github.com/domsvoboda)'s [xodus-nexus](https://github.com/domsvoboda/xodus-nexus) modules (LGPL-2.1-or-later), including `wintypes.dll`. Minecraft's GameInput setup was checked against [@Wyze3306](https://github.com/Wyze3306)'s [BedrockOnLinux](https://github.com/Wyze3306/BedrockOnLinux) (MIT).
|
||||
|
||||
@@ -7,6 +7,7 @@ import os
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import stat
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
@@ -291,6 +292,8 @@ def exited(argv, code=0):
|
||||
compat_data = os.environ.get("STEAM_COMPAT_DATA_PATH")
|
||||
if compat_data:
|
||||
(Path(compat_data) / "pfx" / ROCKSTAR_FOLDER / "launch.json").unlink(missing_ok=True)
|
||||
for line in rockstar_launcher_log(compat_data):
|
||||
log("rockstar launcher: " + line)
|
||||
return 0
|
||||
if found is not None and str(found[1].get("store")) == "epic" and os.environ.get(EPIC_HANDLED) != "1" \
|
||||
and os.access(EPIC_CLIENT, os.X_OK):
|
||||
@@ -319,6 +322,29 @@ ROCKSTAR_TITLES = {"gta3": "Grand Theft Auto III", "gtavc": "Grand Theft Auto: V
|
||||
"gta4": "Grand Theft Auto IV", "lanoire": "LANoireMTL"}
|
||||
|
||||
|
||||
def rockstar_launcher_log(compat_data, limit=65536):
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
target = pfx / ROCKSTAR_FOLDER
|
||||
if not target.resolve().is_relative_to(pfx.resolve()):
|
||||
return []
|
||||
path = target / "launcher.log"
|
||||
try:
|
||||
descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)
|
||||
except OSError:
|
||||
return []
|
||||
try:
|
||||
if not stat.S_ISREG(os.fstat(descriptor).st_mode):
|
||||
return []
|
||||
with os.fdopen(descriptor, "rb", closefd=False) as source:
|
||||
data = source.read(limit)
|
||||
path.unlink(missing_ok=True)
|
||||
except OSError:
|
||||
return []
|
||||
finally:
|
||||
os.close(descriptor)
|
||||
return [line.strip() for line in data.decode("utf-8", "replace").splitlines() if line.strip()]
|
||||
|
||||
|
||||
def rockstar_sdk(folder, sidecar):
|
||||
if str(sidecar.get("id")) in ("gta4", "lanoire"):
|
||||
return True
|
||||
@@ -454,6 +480,7 @@ def prepare_rockstar(folder, sidecar, compat_data, launch_dir, proton="", ask_ap
|
||||
return "invalid-service-path"
|
||||
config = target / "launch.json"
|
||||
config.unlink(missing_ok=True)
|
||||
(target / "launcher.log").unlink(missing_ok=True)
|
||||
legacy = str(sidecar.get("id")) in ROCKSTAR_TITLES
|
||||
sdk = rockstar_sdk(folder, sidecar)
|
||||
title = ROCKSTAR_TITLES.get(str(sidecar.get("id")))
|
||||
|
||||
@@ -86,6 +86,7 @@ bl_run() {
|
||||
set -- /usr/local/bin/droiddeck-steamvr-game "$@"
|
||||
fi
|
||||
if [ -n "${BL_STORE_EXIT:-}" ]; then
|
||||
trap : INT TERM HUP
|
||||
"$@"
|
||||
rc=$?
|
||||
/usr/local/bin/droiddeck-store-launch --exited --code "$rc" "${BL_STORE_ARGS[@]}" || true
|
||||
|
||||
@@ -6,7 +6,7 @@ The handoff is mode 0600, expires after 90 seconds and is deleted before startin
|
||||
|
||||
GTA III, Vice City and San Andreas use body-length MTLX replies. GTA IV and L.A. Noire use total-length, terminated replies. Titles with installed Social Club metadata or SDK binaries use the SDK IPC adapter, including user-info, login, ticket, initialization and authorized title-state synchronization. The title metadata supplies the ROS identity and principal executable; it is checked against Rockstar's catalog before title authorization. Other titles retain Play and Steam shortcuts and attempt the normal executable launch path.
|
||||
|
||||
The SDK runtime is extracted from the game's own Social-Club-Setup.exe when present. Architecture-specific payloads are staged into the prefix, archive paths and sizes are checked, interrupted copies are retried, and both registry views are registered. The helper discovers launcher identity pipe names in the game executable and answers bounded INIT challenges from the launched process. No vendor executables or runtime files are bundled with this tool. SDK initialization has a 90-second deadline. SDK wire tests and fixture clients do not establish gameplay compatibility for every title; per-title ROS ticket exchange and secondary SDK channels remain unverified.
|
||||
The SDK runtime is extracted from the game's own Social-Club-Setup.exe when present. Architecture-specific payloads are staged into the prefix, archive paths and sizes are checked, interrupted copies are retried, and both registry views are registered. The helper discovers launcher identity pipe names in the game executable and the executables beside it, because protected game executables resolve that name only at run time, and answers bounded INIT challenges from the launched process. No vendor executables or runtime files are bundled with this tool. SDK initialization has a 90-second deadline. SDK wire tests and fixture clients do not establish gameplay compatibility for every title; per-title ROS ticket exchange and secondary SDK channels remain unverified.
|
||||
|
||||
GTA III defaults to full x87 precision for FEX before Wine starts, because reduced precision crashed new-game initialization on the test device. San Andreas defaults to WineD3D, because DXVK intermittently corrupted its textures; full precision and conservative memory ordering did not prevent that corruption. These defaults use DroidDeck's per-game settings and preserve explicit per-game overrides.
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const LIMIT: usize = 4096;
|
||||
|
||||
@@ -10,7 +12,13 @@ fn invalid() -> io::Error {
|
||||
)
|
||||
}
|
||||
|
||||
fn collect(bytes: &[u8], names: &mut BTreeSet<String>) {
|
||||
type Names = BTreeMap<String, String>;
|
||||
|
||||
const SCAN_LIMIT: u64 = 256 * 1024 * 1024;
|
||||
const NAME_LIMIT: usize = 4;
|
||||
const SIBLING_LIMIT: usize = 32;
|
||||
|
||||
fn collect(bytes: &[u8], names: &mut Names) {
|
||||
let prefix = br"\\.\pipe\";
|
||||
for (index, window) in bytes.windows(prefix.len()).enumerate() {
|
||||
if window != prefix {
|
||||
@@ -28,44 +36,106 @@ fn collect(bytes: &[u8], names: &mut BTreeSet<String>) {
|
||||
{
|
||||
let name = std::str::from_utf8(name).unwrap();
|
||||
if name.ends_with("LauncherPipe") || name.ends_with("Launcher_Pipe") {
|
||||
names.insert(name.to_owned());
|
||||
names
|
||||
.entry(name.to_ascii_lowercase())
|
||||
.or_insert_with(|| name.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pipe_names(reader: &mut impl Read) -> io::Result<Vec<String>> {
|
||||
let mut names = BTreeSet::new();
|
||||
pub fn title_pipe_names(exe: &Path) -> io::Result<Vec<String>> {
|
||||
discover(exe, SCAN_LIMIT)
|
||||
}
|
||||
|
||||
fn discover(exe: &Path, limit: u64) -> io::Result<Vec<String>> {
|
||||
let mut names = Names::new();
|
||||
let mut principal = limit;
|
||||
scan(&mut File::open(exe)?, &mut names, &mut principal)?;
|
||||
let mut extra = Names::new();
|
||||
let mut budget = limit;
|
||||
for path in siblings(exe) {
|
||||
if extra.len() >= NAME_LIMIT || budget == 0 {
|
||||
break;
|
||||
}
|
||||
let Ok(mut file) = File::open(&path) else {
|
||||
continue;
|
||||
};
|
||||
if !file
|
||||
.metadata()
|
||||
.is_ok_and(|metadata| metadata.len() <= budget)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let mut own = Names::new();
|
||||
if scan(&mut file, &mut own, &mut budget).is_err() {
|
||||
continue;
|
||||
}
|
||||
for (key, name) in own {
|
||||
if extra.len() < NAME_LIMIT && !names.contains_key(&key) {
|
||||
extra.entry(key).or_insert(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
names.append(&mut extra);
|
||||
Ok(names.into_values().collect())
|
||||
}
|
||||
|
||||
fn siblings(exe: &Path) -> Vec<PathBuf> {
|
||||
let Some(entries) = exe.parent().and_then(|folder| fs::read_dir(folder).ok()) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut paths: Vec<_> = entries
|
||||
.flatten()
|
||||
.filter(|entry| entry.file_type().is_ok_and(|kind| kind.is_file()))
|
||||
.map(|entry| entry.path())
|
||||
.filter(|path| {
|
||||
path != exe
|
||||
&& path
|
||||
.extension()
|
||||
.is_some_and(|extension| extension.eq_ignore_ascii_case("exe"))
|
||||
})
|
||||
.collect();
|
||||
paths.sort();
|
||||
paths.truncate(SIBLING_LIMIT);
|
||||
paths
|
||||
}
|
||||
|
||||
fn scan(reader: &mut impl Read, names: &mut Names, budget: &mut u64) -> io::Result<()> {
|
||||
let mut carry = Vec::new();
|
||||
let mut chunk = [0; 65536];
|
||||
let mut total = 0usize;
|
||||
loop {
|
||||
let count = reader.read(&mut chunk)?;
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
total += count;
|
||||
if total > 256 * 1024 * 1024 {
|
||||
return Err(invalid());
|
||||
}
|
||||
*budget = budget.checked_sub(count as u64).ok_or_else(invalid)?;
|
||||
carry.extend_from_slice(&chunk[..count]);
|
||||
collect(&carry, &mut names);
|
||||
collect(&carry, names);
|
||||
for offset in 0..2 {
|
||||
let ascii: Vec<_> = carry[offset..]
|
||||
.chunks_exact(2)
|
||||
.map(|pair| if pair[1] == 0 { pair[0] } else { 0 })
|
||||
.collect();
|
||||
collect(&ascii, &mut names);
|
||||
collect(&ascii, names);
|
||||
}
|
||||
if names.len() > 4 {
|
||||
if names.len() > NAME_LIMIT {
|
||||
return Err(invalid());
|
||||
}
|
||||
carry.drain(..carry.len().saturating_sub(256));
|
||||
}
|
||||
Ok(names.into_iter().collect())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn exchange(reader: &mut impl Read) -> io::Result<Vec<u8>> {
|
||||
exchange_observed(reader, |_| {})
|
||||
}
|
||||
|
||||
pub fn exchange_observed(
|
||||
reader: &mut impl Read,
|
||||
mut observe: impl FnMut(&'static str),
|
||||
) -> io::Result<Vec<u8>> {
|
||||
observe("reading header");
|
||||
let mut header = [0; 4];
|
||||
reader.read_exact(&mut header)?;
|
||||
let framed = header != *b"INIT";
|
||||
@@ -75,9 +145,11 @@ pub fn exchange(reader: &mut impl Read) -> io::Result<Vec<u8>> {
|
||||
return Err(invalid());
|
||||
}
|
||||
let mut bytes = vec![0; size];
|
||||
observe("reading framed request");
|
||||
reader.read_exact(&mut bytes)?;
|
||||
bytes
|
||||
} else {
|
||||
observe("reading unframed request");
|
||||
let mut bytes = header.to_vec();
|
||||
let mut byte = [0];
|
||||
reader.read_exact(&mut byte)?;
|
||||
@@ -108,6 +180,7 @@ pub fn exchange(reader: &mut impl Read) -> io::Result<Vec<u8>> {
|
||||
{
|
||||
return Err(invalid());
|
||||
}
|
||||
observe("request validated");
|
||||
let mut reply = b"TINI:launcher:".to_vec();
|
||||
reply.extend_from_slice(challenge);
|
||||
if framed {
|
||||
@@ -134,12 +207,200 @@ mod tests {
|
||||
}
|
||||
bytes.extend_from_slice(br"\\.\pipe\..\outsideLauncherPipe");
|
||||
bytes.push(0);
|
||||
let mut names = Names::new();
|
||||
scan(&mut Cursor::new(bytes), &mut names, &mut SCAN_LIMIT.clone()).unwrap();
|
||||
assert_eq!(
|
||||
pipe_names(&mut Cursor::new(bytes)).unwrap(),
|
||||
names.into_values().collect::<Vec<_>>(),
|
||||
["GameLauncherPipe", "OtherLauncher_Pipe"]
|
||||
);
|
||||
}
|
||||
|
||||
fn folder(name: &str) -> std::path::PathBuf {
|
||||
let path =
|
||||
std::env::temp_dir().join(format!("droiddeck-identity-{name}-{}", std::process::id()));
|
||||
let _ = fs::remove_dir_all(&path);
|
||||
fs::create_dir(&path).unwrap();
|
||||
path
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_names_include_sibling_launcher_executables() {
|
||||
let root = folder("siblings");
|
||||
let game = root.join("Game.exe");
|
||||
fs::write(&game, b"MZ obfuscated").unwrap();
|
||||
fs::write(
|
||||
root.join("TitleLauncher.exe"),
|
||||
[br"MZ \\.\pipe\TitleLauncher_Pipe".as_slice(), b"\0"].concat(),
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
root.join("Data.dat"),
|
||||
[br"\\.\pipe\DataLauncher_Pipe".as_slice(), b"\0"].concat(),
|
||||
)
|
||||
.unwrap();
|
||||
fs::create_dir(root.join("Folder.exe")).unwrap();
|
||||
let names = title_pipe_names(&game).unwrap();
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
assert_eq!(names, ["TitleLauncher_Pipe"]);
|
||||
}
|
||||
|
||||
fn executable(path: &Path, names: &[&str]) {
|
||||
let mut bytes = b"MZ ".to_vec();
|
||||
for name in names {
|
||||
bytes.extend_from_slice(br"\\.\pipe\");
|
||||
bytes.extend_from_slice(name.as_bytes());
|
||||
bytes.push(0);
|
||||
}
|
||||
fs::write(path, bytes).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_names_keep_the_game_executable_names_and_limits() {
|
||||
let root = folder("principal");
|
||||
let game = root.join("Game.exe");
|
||||
executable(&game, &["GameLauncherPipe"]);
|
||||
fs::write(root.join("Tool.exe"), b"MZ plain").unwrap();
|
||||
assert_eq!(title_pipe_names(&game).unwrap(), ["GameLauncherPipe"]);
|
||||
for index in 0..40 {
|
||||
fs::write(root.join(format!("Extra{index:02}.exe")), b"MZ").unwrap();
|
||||
}
|
||||
executable(&root.join("Zz.exe"), &["LateLauncher_Pipe"]);
|
||||
let crowded = title_pipe_names(&game);
|
||||
executable(
|
||||
&game,
|
||||
&[
|
||||
"ALauncherPipe",
|
||||
"BLauncherPipe",
|
||||
"CLauncherPipe",
|
||||
"DLauncherPipe",
|
||||
"ELauncherPipe",
|
||||
],
|
||||
);
|
||||
let overfull = title_pipe_names(&game);
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
assert_eq!(crowded.unwrap(), ["GameLauncherPipe"]);
|
||||
assert!(overfull.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_names_skip_siblings_that_cannot_be_scanned() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let root = folder("unscannable");
|
||||
let game = root.join("Game.exe");
|
||||
executable(&game, &["GameLauncherPipe"]);
|
||||
let locked = root.join("Locked.exe");
|
||||
executable(&locked, &["LockedLauncher_Pipe"]);
|
||||
fs::set_permissions(&locked, fs::Permissions::from_mode(0o000)).unwrap();
|
||||
let locked_open = File::open(&locked).is_ok();
|
||||
File::create(root.join("Huge.exe"))
|
||||
.unwrap()
|
||||
.set_len(SCAN_LIMIT + 1)
|
||||
.unwrap();
|
||||
executable(
|
||||
&root.join("Noisy.exe"),
|
||||
&[
|
||||
"NALauncherPipe",
|
||||
"NBLauncherPipe",
|
||||
"NCLauncherPipe",
|
||||
"NDLauncherPipe",
|
||||
"NELauncherPipe",
|
||||
],
|
||||
);
|
||||
let names = title_pipe_names(&game);
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
let mut expected = vec!["GameLauncherPipe".to_owned()];
|
||||
if locked_open {
|
||||
expected.push("LockedLauncher_Pipe".to_owned());
|
||||
}
|
||||
assert_eq!(names.unwrap(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_names_bound_the_bytes_read_from_siblings() {
|
||||
let root = folder("budget");
|
||||
let game = root.join("Game.exe");
|
||||
executable(&game, &["GameLauncherPipe"]);
|
||||
executable(&root.join("First.exe"), &["FirstLauncherPipe"]);
|
||||
executable(&root.join("Second.exe"), &["SecondLauncherPipe"]);
|
||||
let size = fs::metadata(root.join("First.exe")).unwrap().len();
|
||||
let names = discover(&game, size + 8);
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
assert_eq!(names.unwrap(), ["FirstLauncherPipe", "GameLauncherPipe"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_names_merge_case_insensitively_and_cap_sibling_names() {
|
||||
let root = folder("merge");
|
||||
let game = root.join("Game.exe");
|
||||
executable(
|
||||
&game,
|
||||
&[
|
||||
"ALauncherPipe",
|
||||
"BLauncherPipe",
|
||||
"CLauncherPipe",
|
||||
"GTAVLauncher_Pipe",
|
||||
],
|
||||
);
|
||||
executable(
|
||||
&root.join("A.exe"),
|
||||
&["gtavLauncher_Pipe", "ELauncherPipe", "FLauncherPipe"],
|
||||
);
|
||||
executable(
|
||||
&root.join("B.exe"),
|
||||
&["GLauncherPipe", "HLauncherPipe", "ILauncherPipe"],
|
||||
);
|
||||
let names = title_pipe_names(&game);
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
assert_eq!(
|
||||
names.unwrap(),
|
||||
[
|
||||
"ALauncherPipe",
|
||||
"BLauncherPipe",
|
||||
"CLauncherPipe",
|
||||
"ELauncherPipe",
|
||||
"FLauncherPipe",
|
||||
"GLauncherPipe",
|
||||
"GTAVLauncher_Pipe",
|
||||
"HLauncherPipe"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identity_observations_preserve_replies_and_report_incomplete_stages() {
|
||||
let request = b"INIT:private-challenge:";
|
||||
let mut framed = (request.len() as u32).to_le_bytes().to_vec();
|
||||
framed.extend_from_slice(request);
|
||||
for (bytes, stage) in [
|
||||
(request.to_vec(), "reading unframed request"),
|
||||
(framed, "reading framed request"),
|
||||
] {
|
||||
let mut stages = Vec::new();
|
||||
let reply =
|
||||
exchange_observed(&mut Cursor::new(&bytes), |stage| stages.push(stage)).unwrap();
|
||||
assert_eq!(reply, exchange(&mut Cursor::new(&bytes)).unwrap());
|
||||
assert_eq!(stages, ["reading header", stage, "request validated"]);
|
||||
for end in 0..bytes.len() {
|
||||
let mut stages = Vec::new();
|
||||
assert!(exchange_observed(&mut Cursor::new(&bytes[..end]), |stage| {
|
||||
stages.push(stage)
|
||||
})
|
||||
.is_err());
|
||||
assert_eq!(
|
||||
stages,
|
||||
if end < 4 {
|
||||
vec!["reading header"]
|
||||
} else {
|
||||
vec!["reading header", stage]
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
let mut stages = Vec::new();
|
||||
assert!(exchange_observed(&mut Cursor::new([255; 4]), |stage| stages.push(stage)).is_err());
|
||||
assert_eq!(stages, ["reading header"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identity_replies_echo_only_a_valid_challenge() {
|
||||
struct Split<R>(R);
|
||||
|
||||
@@ -146,14 +146,21 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||
None
|
||||
};
|
||||
let mut identity_listeners = Vec::new();
|
||||
let mut identity_names = Vec::new();
|
||||
if session.is_some() {
|
||||
for name in
|
||||
droiddeck_rockstar_launcher::identity::pipe_names(&mut std::fs::File::open(&exe)?)?
|
||||
{
|
||||
identity_listeners.push(Listener::new(&name, Duration::from_secs(90))?);
|
||||
identity_names = droiddeck_rockstar_launcher::identity::title_pipe_names(&exe)?;
|
||||
for name in &identity_names {
|
||||
identity_listeners.push(Listener::new(name, Duration::from_secs(90))?);
|
||||
}
|
||||
}
|
||||
log("launcher pipes created");
|
||||
log(&format!(
|
||||
"launcher pipes created, identity: {}",
|
||||
if identity_names.is_empty() {
|
||||
"none".to_owned()
|
||||
} else {
|
||||
identity_names.join(", ")
|
||||
}
|
||||
));
|
||||
let mut command = std::process::Command::new(exe);
|
||||
command.current_dir(workdir).args(args?);
|
||||
if session.is_some() {
|
||||
@@ -162,26 +169,35 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||
let mut child = command.spawn()?;
|
||||
let pid = child.id();
|
||||
log("game process started");
|
||||
for listener in identity_listeners {
|
||||
for (name, listener) in identity_names.into_iter().zip(identity_listeners) {
|
||||
std::thread::spawn(move || {
|
||||
let serve = || -> std::io::Result<()> {
|
||||
log(&format!("launcher identity {name}: waiting for connection"));
|
||||
let mut pipe = listener.accept()?.with_deadline(Duration::from_secs(90));
|
||||
log(&format!("launcher identity {name}: connected"));
|
||||
if pipe.client_pid()? != pid {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::PermissionDenied,
|
||||
"unexpected launcher identity client",
|
||||
));
|
||||
}
|
||||
let reply = droiddeck_rockstar_launcher::identity::exchange(&mut pipe)?;
|
||||
log(&format!("launcher identity {name}: client verified"));
|
||||
let reply =
|
||||
droiddeck_rockstar_launcher::identity::exchange_observed(&mut pipe, |stage| {
|
||||
log(&format!("launcher identity {name}: {stage}"))
|
||||
})?;
|
||||
log(&format!("launcher identity {name}: writing reply"));
|
||||
pipe.write_all(&reply)?;
|
||||
log("launcher identity challenge complete");
|
||||
log(&format!("launcher identity {name}: challenge complete"));
|
||||
pipe = pipe.with_timeout(Duration::from_secs(86400));
|
||||
let mut progress = [0; 4096];
|
||||
while matches!(pipe.read(&mut progress), Ok(size) if size > 0) {}
|
||||
Ok(())
|
||||
};
|
||||
if let Err(error) = serve() {
|
||||
log(&format!("launcher identity exchange ended: {error}"));
|
||||
log(&format!(
|
||||
"launcher identity {name}: exchange ended: {error}"
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -256,7 +272,9 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||
}
|
||||
let _ = result.send(outcome);
|
||||
});
|
||||
Ok(wait_for_game(&mut child, handshake)?.code().unwrap_or(1))
|
||||
let code = wait_for_game(&mut child, handshake)?.code().unwrap_or(1);
|
||||
log(&format!("game exited with code {code}"));
|
||||
Ok(code)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
import shlex
|
||||
import subprocess
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
@@ -317,6 +319,33 @@ class Launchers(unittest.TestCase):
|
||||
self.assertIn('bl_store_launch() {', compat.BL_STORE_SETUP)
|
||||
self.assertIn('waitforexitandrun', compat.BL_STORE_SETUP)
|
||||
|
||||
def run_store_game(self, game, store_exit=True):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
hook = Path(root) / 'hook'
|
||||
record = Path(root) / 'exited'
|
||||
hook.write_text('#!/bin/sh\necho "$@" > "%s"\n' % record)
|
||||
hook.chmod(0o755)
|
||||
setup = compat.BL_STORE_SETUP.replace('/usr/local/bin/droiddeck-store-launch --exited', str(hook) + ' --exited')
|
||||
script = setup + '\nBL_STORE_ARGS=(game.bat)\n%sbl_run sh -c %s\nexit 99\n' % (
|
||||
'BL_STORE_EXIT=1\n' if store_exit else '', shlex.quote(game))
|
||||
done = subprocess.run(['bash', '-c', script], start_new_session=True, timeout=20)
|
||||
return done.returncode, record.read_text().split() if record.exists() else None
|
||||
|
||||
def test_a_store_game_ended_by_a_group_signal_still_reports_its_exit(self):
|
||||
for signal_name, code in (('INT', '130'), ('TERM', '143'), ('HUP', '129')):
|
||||
rc, hook = self.run_store_game('kill -%s 0; sleep 5' % signal_name)
|
||||
self.assertEqual(['--exited', '--code', code, 'game.bat'], hook, signal_name)
|
||||
self.assertEqual(int(code), rc, signal_name)
|
||||
|
||||
def test_a_store_game_that_exits_by_itself_reports_its_code_once(self):
|
||||
self.assertEqual((3, ['--exited', '--code', '3', 'game.bat']), self.run_store_game('exit 3'))
|
||||
|
||||
def test_other_games_still_replace_the_wrapper_without_the_exit_hook(self):
|
||||
self.assertEqual((4, None), self.run_store_game('exit 4', store_exit=False))
|
||||
rc, hook = self.run_store_game('kill -INT 0; sleep 5', store_exit=False)
|
||||
self.assertIsNone(hook)
|
||||
self.assertEqual(-2, rc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -6,7 +6,7 @@ import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from test_store_launch import store
|
||||
from test_store_launch import game, store
|
||||
|
||||
|
||||
class RockstarLaunch(unittest.TestCase):
|
||||
@@ -182,6 +182,70 @@ class RockstarLaunch(unittest.TestCase):
|
||||
self.assertEqual([], requests)
|
||||
self.assertFalse(config.exists())
|
||||
|
||||
def test_each_launch_starts_a_fresh_launcher_log(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
stale = []
|
||||
|
||||
def ask(channel, request, timeout):
|
||||
stale.append((config.parent / 'launcher.log').exists())
|
||||
return answer
|
||||
|
||||
folder, sidecar, prefix, service, answer = self.setup_game(root)
|
||||
config = prefix / 'pfx' / store.ROCKSTAR_FOLDER / 'launch.json'
|
||||
config.parent.mkdir(parents=True)
|
||||
(config.parent / 'launcher.log').write_bytes(b'x' * 70000)
|
||||
with patch.object(store, 'ROCKSTAR_SERVICE', service), patch.object(store, 'rockstar_registry', return_value=True):
|
||||
result = store.prepare_rockstar(folder, sidecar, str(prefix), str(Path(root) / 'channel'), ask_app=ask)
|
||||
self.assertEqual('ready', result)
|
||||
self.assertEqual([False], stale)
|
||||
|
||||
def exit_game(self, root, store_id, log_text=None, link=None):
|
||||
folder = game(root, store_id=store_id, ident='gta5')
|
||||
prefix = Path(root) / 'prefix'
|
||||
target = prefix / 'pfx' / store.ROCKSTAR_FOLDER
|
||||
target.mkdir(parents=True)
|
||||
if log_text is not None:
|
||||
(target / 'launcher.log').write_text(log_text)
|
||||
if link is not None:
|
||||
(target / 'launcher.log').symlink_to(link)
|
||||
lines = []
|
||||
with patch.dict(os.environ, {'BL_LAUNCH_DIR': str(Path(root) / 'session'), 'STEAM_COMPAT_DATA_PATH': str(prefix)}), \
|
||||
patch.object(store, 'ask', return_value={'ok': True}), patch.object(store, 'log', lines.append):
|
||||
self.assertEqual(0, store.main(['--exited', str(folder / '.droiddeck-launch.bat')]))
|
||||
return lines, target / 'launcher.log'
|
||||
|
||||
def test_launcher_log_reaches_the_session_log_when_the_game_exits(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
text = 'launch handoff accepted\r\nlauncher pipes created, identity: none\r\n\r\ngame exited with code 0\r\n'
|
||||
lines, path = self.exit_game(root, 'rockstar', log_text=text)
|
||||
self.assertEqual(['rockstar launcher: launch handoff accepted',
|
||||
'rockstar launcher: launcher pipes created, identity: none',
|
||||
'rockstar launcher: game exited with code 0'], lines)
|
||||
self.assertFalse(path.exists())
|
||||
|
||||
def test_launcher_log_relay_does_not_follow_links(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
outside = Path(root) / 'outside.txt'
|
||||
outside.write_text('private\n')
|
||||
lines, path = self.exit_game(root, 'rockstar', link=outside)
|
||||
self.assertEqual([], lines)
|
||||
self.assertTrue(path.is_symlink())
|
||||
self.assertEqual('private\n', outside.read_text())
|
||||
|
||||
def test_other_stores_do_not_relay_the_launcher_log(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
lines, path = self.exit_game(root, 'gog', log_text='launch handoff accepted\n')
|
||||
self.assertFalse(any(line.startswith('rockstar launcher:') for line in lines))
|
||||
self.assertTrue(path.exists())
|
||||
|
||||
def test_relay_is_bounded(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
prefix = Path(root) / 'prefix'
|
||||
target = prefix / 'pfx' / store.ROCKSTAR_FOLDER
|
||||
target.mkdir(parents=True)
|
||||
(target / 'launcher.log').write_text('a' * 10 + '\n' + 'b' * 100 + '\n')
|
||||
self.assertEqual(['a' * 10, 'b' * 5], store.rockstar_launcher_log(str(prefix), limit=16))
|
||||
|
||||
def test_writes_both_registry_views_and_escapes_values(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder, _, prefix, _, _ = self.setup_game(root)
|
||||
|
||||
Reference in new issue
Block a user