Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Keep game folders open for mods

Leonardo Lobatob83d7c1cc3eb
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index d5d90f0..c69f231 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -138,7 +138,8 @@ std::size_t RebaseCloudIndexes(const std::filesystem::path& saves, const std::st
if (count <= 0) break;
written += static_cast<std::size_t>(count);
}
- const bool ok = written == rewritten.size() && fsync(out) == 0;
+ // The original's mode, whatever the umask took from it.
+ const bool ok = written == rewritten.size() && fchmod(out, info.st_mode & 0777) == 0 && fsync(out) == 0;
if (close(out) != 0 || !ok || rename(temporary.c_str(), path.c_str()) != 0) {
unlink(temporary.c_str());
continue;
@@ -479,7 +480,7 @@ std::string RuntimeHost::KitReplaced(const Composition& c) const {
return "The compatibility kit changed while Playden was running. Quit Playden and start it again.";
}
-std::string RuntimeHost::ApplySteamworks(Composition& c, const rt::RuntimeInstall& record) {
+std::string RuntimeHost::ApplySteamworks(Composition& c, const rt::RuntimeInstall& record, bool steam_account_known) {
if (c.kit) {
std::string reason;
// Media support is an upgrade for older bottles, not a condition to play: a game that doesn't use it
@@ -531,7 +532,11 @@ std::string RuntimeHost::ApplySteamworks(Composition& c, const rt::RuntimeInstal
if (!unpacked.ok) return unpacked.message;
const bool emulate = settings.values.at("steam_features").value == "emulate";
rt::SteamworksResult result;
- if (emulate) {
+ // The emulator's files name the signed-in account; before it is known they keep what Play wrote.
+ const bool emulator_waits = emulate && !steam_account_known;
+ if (emulator_waits) {
+ Log("steamworks app=" + std::to_string(record.app_id) + " mode=emulate waits: the Steam account is not known yet");
+ } else if (emulate) {
rt::SteamworksIdentity identity;
identity.app_id = record.app_id;
{
@@ -546,15 +551,17 @@ std::string RuntimeHost::ApplySteamworks(Composition& c, const rt::RuntimeInstal
} else {
result = rt::RestoreSteamworks(root.string());
}
- std::string changed;
- for (const auto& path : result.changed) changed += (changed.empty() ? "" : ",") + path;
- Log("steamworks app=" + std::to_string(record.app_id) + " mode=" + (emulate ? "emulate" : "game") +
- " found=" + std::to_string(result.found.size()) + " changed=" + (changed.empty() ? "-" : changed) +
- (result.ok ? std::string() : " failed=" + result.message));
- if (!result.ok) return result.message;
+ if (!emulator_waits) {
+ std::string changed;
+ for (const auto& path : result.changed) changed += (changed.empty() ? "" : ",") + path;
+ Log("steamworks app=" + std::to_string(record.app_id) + " mode=" + (emulate ? "emulate" : "game") +
+ " found=" + std::to_string(result.found.size()) + " changed=" + (changed.empty() ? "-" : changed) +
+ (result.ok ? std::string() : " failed=" + result.message));
+ if (!result.ok) return result.message;
+ }
// A game from before Steamworks (no steam_api DLL) checks for Steam through steam.dll instead
// (GUN: "Failed to find Steam."); emulation gives it the minimal one, the game's mode takes it away.
- if (!emulate || result.found.empty()) {
+ if (!emulator_waits && (!emulate || result.found.empty())) {
const auto emulator = config_.steamworks_dir.empty() ? config_.runtime_dir + "/steamworks" : config_.steamworks_dir;
const auto legacy = emulate ? rt::ProvideLegacySteam(root.string(), emulator, programs)
: rt::RemoveLegacySteam(root.string(), programs);
@@ -944,8 +951,105 @@ std::string RuntimeHost::EnsureWritable(const std::string& install_path, const s
return rt::EnsureWritableFolders(folders, config_.as_root, [this](const std::string& line) { Log(line); });
}
-std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInstall& record, bool* published) {
+bool RuntimeHost::NeedsUnownedPublication(const Composition& c, const rt::RuntimeInstall& record) {
+ if (!c.kit || record.state != rt::PreparationState::kReady || record.journal ||
+ !rt::KitCapabilitiesFromManifest(c.kit->capabilities, true).game_root_unowned)
+ return false;
+ return rt::PublishedGameRootUnowned(record, config_.host_namespace_prefix) == std::optional<bool>(false);
+}
+
+void RuntimeHost::OpenGameFolders(const Composition& c, const rt::RuntimeInstall& record) {
+ // Only under an unowned publication: an owned one fails the title's start check at 0777.
+ if (!c.kit || record.install_path.empty() ||
+ !rt::KitCapabilitiesFromManifest(c.kit->capabilities, true).game_root_unowned ||
+ rt::PublishedGameRootUnowned(record, config_.host_namespace_prefix) != std::optional<bool>(true))
+ return;
+ const auto working = WorkingFolder(record.launch_working_directory, record.launch_path, record.launch_in_install_root);
+ auto folder = HostPath(record.install_path);
+ const auto open_up = [this](const std::filesystem::path& path) {
+ struct stat info{};
+ if (lstat(path.c_str(), &info) != 0 || !S_ISDIR(info.st_mode) || info.st_uid != geteuid() ||
+ (info.st_mode & 07777) != 0755)
+ return;
+ const bool opened = chmod(path.c_str(), 0777) == 0;
+ Log("game folder mode 0755 -> 0777 path=" + path.string() + (opened ? "" : " failed errno=" + std::to_string(errno)));
+ };
+ open_up(folder);
+ if (working.empty() || working == ".") return;
+ for (const auto& part : std::filesystem::path(working)) {
+ if (part.empty() || part == "." || part == ".." || part.is_absolute()) return;
+ folder /= part;
+ open_up(folder);
+ }
+}
+
+std::string RuntimeHost::UnlinkDxvkConfig(const rt::RuntimeInstall& record) {
+ if (record.install_path.empty()) return {};
+ const std::filesystem::path working(WorkingFolder(record.launch_working_directory, record.launch_path, record.launch_in_install_root));
+ if (working.is_absolute() ||
+ std::any_of(working.begin(), working.end(), [](const auto& part) { return part == ".."; }))
+ return {};
+ const auto path = HostPath(record.install_path) / working / "dxvk.conf";
+ struct stat info{};
+ if (lstat(path.c_str(), &info) != 0 || !S_ISREG(info.st_mode) || info.st_nlink <= 1) return {};
+ const auto failed = [&](const char* step) {
+ Log("dxvk.conf unlink app=" + std::to_string(record.app_id) + " failed at " + step + " errno=" + std::to_string(errno));
+ return std::string("The game's dxvk.conf has more than one link and could not be replaced by a copy.");
+ };
+ constexpr off_t kMaxBytes = 256 * 1024;
+ if (info.st_size > kMaxBytes) return failed("size");
+ std::string bytes;
+ {
+ const int in = open(path.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
+ struct stat opened{};
+ if (in < 0) return failed("open");
+ if (fstat(in, &opened) != 0 || opened.st_ino != info.st_ino || opened.st_dev != info.st_dev) {
+ close(in);
+ return failed("identity");
+ }
+ char buffer[16384];
+ for (;;) {
+ const auto count = read(in, buffer, sizeof(buffer));
+ if (count < 0 && errno == EINTR) continue;
+ if (count < 0 || bytes.size() + static_cast<std::size_t>(std::max<ssize_t>(count, 0)) > std::size_t(kMaxBytes)) {
+ close(in);
+ return failed("read");
+ }
+ if (count == 0) break;
+ bytes.append(buffer, static_cast<std::size_t>(count));
+ }
+ close(in);
+ }
+ const auto temporary = path.parent_path() / ".dxvk.conf.playden-unlink";
+ unlink(temporary.c_str());
+ const int out = open(temporary.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600);
+ if (out < 0) return failed("create");
+ std::size_t written = 0;
+ while (written < bytes.size()) {
+ const auto count = write(out, bytes.data() + written, bytes.size() - written);
+ if (count < 0 && errno == EINTR) continue;
+ if (count <= 0) break;
+ written += static_cast<std::size_t>(count);
+ }
+ const bool ok = written == bytes.size() && fchmod(out, info.st_mode & 0777) == 0 && fsync(out) == 0;
+ if (close(out) != 0 || !ok || rename(temporary.c_str(), path.c_str()) != 0) {
+ unlink(temporary.c_str());
+ return failed("write");
+ }
+ Log("dxvk.conf unlink app=" + std::to_string(record.app_id) + " links=" + std::to_string(info.st_nlink) +
+ " replaced by a copy path=" + path.string());
+ return {};
+}
+
+std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInstall& record, bool* published,
+ bool steam_account_known, bool* prepare_again) {
if (published) *published = false;
+ if (prepare_again) *prepare_again = false;
+ // Refusals only a new preparation gets past (the title's recipe or settings can't be published again).
+ const auto again = [prepare_again](std::string message) {
+ if (prepare_again) *prepare_again = true;
+ return message;
+ };
const auto saved = config_.settings_record ? config_.settings_record(record.app_id).value_or(rt::GameSettingsRecord{})
: rt::GameSettingsRecord{};
// A recipe this kit cannot run is refused before the game's files or bottle change.
@@ -956,17 +1060,21 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
// A game whose folder moved (RuntimeInstall::moved_from) is published again at its revision, so
// its descriptor, profile and dxvk.conf name the new folder.
const bool moved = !record.moved_from.empty();
+ // So is an owned publication the kit can replace by an unowned one (folders opened for mods).
+ const bool unowned_upgrade = !moved && NeedsUnownedPublication(c, record);
+ if (unowned_upgrade) Log("settings update app=" + std::to_string(record.app_id) + " publishes the game folder unowned");
// "Steam features" only swaps the game's own files, so it follows the saved value at once.
- if (saved.revision <= record.settings_revision && !moved) return ApplySteamworks(c, record);
+ if (saved.revision <= record.settings_revision && !moved && !unowned_upgrade)
+ return ApplySteamworks(c, record, steam_account_known);
if (!c.kit) return "No verified compatibility kit is installed.";
if (saved.revision < record.settings_revision)
- return "The game's saved settings are older than its PS5 title's; prepare it again.";
+ return again("The game's saved settings are older than its PS5 title's; prepare it again.");
const rt::GameRecipe* recipe = nullptr;
for (const auto& candidate : c.recipes)
if (candidate.app_id == record.app_id && candidate.id == record.recipe_id &&
std::to_string(candidate.version) == record.recipe_version)
recipe = &candidate;
- if (!recipe) return "Playden no longer knows how to start this game; prepare it again.";
+ if (!recipe) return again("Playden no longer knows how to start this game; prepare it again.");
const rt::SettingsPreset* preset = nullptr;
for (const auto& candidate : c.presets)
if (candidate.id == saved.preset_id) preset = &candidate;
@@ -1002,7 +1110,9 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
if (!folder.empty() && (lstat((HostPath(record.install_path) / folder).c_str(), &folder_info) != 0 ||
!S_ISDIR(folder_info.st_mode)))
return "The program folder " + folder + " chosen in Game settings is missing.";
- const auto records_ownership = platform::RecordsOwnership(HostPath(record.install_path));
+ // A kit that admits unowned game folders gets them as they are (mods, FTP edits).
+ const auto records_ownership = kit.game_root_unowned ? std::optional<bool>(false)
+ : platform::RecordsOwnership(HostPath(record.install_path));
if (records_ownership && *records_ownership)
if (const auto refused = TightenWorkingFolder(HostPath(record.install_path),
WorkingFolder(launch.working_directory, launch.executable,
@@ -1020,8 +1130,14 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
}
}
}
+ // An unowned folder is published as it is, so one made over FTP (root's, 0755) is opened up
+ // before dxvk.conf is written into it, as preparation does.
+ if (kit.game_root_unowned) {
+ const auto working = WorkingFolder(next.launch_working_directory, next.launch_path, next.launch_in_install_root);
+ if (const auto unwritable = EnsureWritable(next.install_path, working); !unwritable.empty()) return unwritable;
+ }
// SteamStub unpacking and the Steam emulator follow the program that starts now.
- if (const auto steamworks = ApplySteamworks(c, next); !steamworks.empty()) return steamworks;
+ if (const auto steamworks = ApplySteamworks(c, next, steam_account_known); !steamworks.empty()) return steamworks;
rt::SettingsLaunchInput input;
input.recipe = recipe;
input.record = saved;
@@ -1047,11 +1163,11 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
std::string reason;
if (!rt::BuildSettingsLaunchPlan(input, &plan, &reason)) {
Log("settings update plan refused app=" + std::to_string(record.app_id) + ": " + reason);
- return "The settings could not be applied: " + reason;
+ return again("The settings could not be applied: " + reason);
}
if (plan.app_id != record.app_id || plan.recipe_id != record.recipe_id || plan.recipe_version != record.recipe_version ||
plan.launch_entry_id != next.launch_entry_id || plan.profile_id != record.default_profile_id)
- return "The settings no longer match this game's PS5 title; prepare it again.";
+ return again("The settings no longer match this game's PS5 title; prepare it again.");
const auto transaction = config_.uuid();
if (!transaction) return "No secure random source for the settings update.";
rt::SettingsPublicationRequest request;
@@ -1079,6 +1195,7 @@ std::string RuntimeHost::RepublishSettings(Composition& c, const rt::RuntimeInst
// A failed update keeps its journal, so Play waits until Resume on the PS5 title finishes it.
if (resumed.state != rt::PackageActionState::kComplete) return "The settings could not be applied: " + resumed.message;
if (published) *published = true;
+ if (const auto current = c.records.Find(record.install_id)) OpenGameFolders(c, *current);
if (moved) FinishGamesMove(c);
return {};
}
@@ -1251,13 +1368,19 @@ void RuntimeHost::RunPlay(Composition& c, std::uint32_t app_id) {
settings = "This game needs an update for Playden 0.5 first: " + (busy.empty() ? "Close the game first." : busy);
} else {
Publish([&](RuntimeSnapshot& s) { s.play_progress[app_id] = kPlayUpdatingForLayout; });
- settings = RepublishSettings(c, *record);
+ bool again = false;
+ settings = RepublishSettings(c, *record, nullptr, true, &again);
Publish([&](RuntimeSnapshot& s) { s.play_progress.erase(app_id); });
- if (!settings.empty()) settings = "This game could not be updated for Playden 0.5: " + settings;
+ if (!settings.empty())
+ settings = "This game could not be updated for Playden 0.5: " + settings +
+ (again ? " Press Update on the game page to prepare it again." : "");
Log("play moved app=" + std::to_string(app_id) + " " + (settings.empty() ? "republished" : settings));
}
} else if (idle) {
- settings = RepublishSettings(c, *record);
+ bool again = false;
+ settings = RepublishSettings(c, *record, nullptr, true, &again);
+ if (again && NeedsUnownedPublication(c, *record))
+ settings += " Press Update on the game page to prepare it again.";
}
result = settings.empty() ? c.launch->Request(record->install_id)
: rt::LaunchResult::Failure(rt::LaunchError::kPreflight, settings);
@@ -1584,13 +1707,21 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&
if (auto unwritable = EnsureWritable(request.install_path, working); !unwritable.empty()) return unwritable;
return game_root_owned ? TightenWorkingFolder(HostPath(request.install_path), working) : std::string();
};
- // Settings publication writes dxvk.conf into the game folder and requires that
+ // A kit with game-root-unowned admits a game folder of any owner and mode (publication
+ // metadata schema 3), so files a user adds or changes over FTP (mods) are left as they are.
+ // Otherwise settings publication writes dxvk.conf into the game folder and requires that
// folder to belong to the app user without group/other write access. Console
// downloads are created world-writable; tighten an owned root to 0755. A root
// owned by anyone else is refused, never taken over. A drive that records no
// owners or permissions (exFAT) has nothing to check or tighten; the kit must
- // then admit such folders (publication metadata schema 3).
- {
+ // then admit such folders.
+ const bool unowned_kit = rt::KitCapabilitiesFromManifest(c.kit->capabilities, true).game_root_unowned;
+ if (unowned_kit) {
+ struct stat info{};
+ if (lstat(HostPath(request.install_path).c_str(), &info) != 0 || !S_ISDIR(info.st_mode))
+ return "The game's folder is unavailable.";
+ game_root_owned = false;
+ } else {
const auto root = config_.host_namespace_prefix.empty()
? std::filesystem::path(request.install_path)
: config_.host_namespace_prefix / std::filesystem::path(request.install_path).relative_path();
@@ -1717,14 +1848,31 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&
if (refreshed.state != rt::PackageActionState::kComplete) return refreshed.message;
changed = true;
}
- // A game whose folder moved in 0.5 is published again for the new folder first.
- if (!existing->moved_from.empty()) {
- if (const auto refused = RepublishSettings(c, *existing); !refused.empty()) return refused;
+ // A game whose folder moved in 0.5 is published again for the new folder first, and an
+ // owned publication again as unowned.
+ if (!existing->moved_from.empty() || NeedsUnownedPublication(c, *existing)) {
+ bool again = false;
+ if (const auto refused = RepublishSettings(c, *existing, nullptr, true, &again); !refused.empty()) {
+ if (!again) return refused;
+ // Its publication can't be redone (settings older than its title, a recipe Playden no
+ // longer has): it is prepared again, as Recreate bottle does. The title goes, the bottle
+ // is kept for its saves, and a new title is made from the game's folder.
+ Log("prepare again app=" + std::to_string(request.app_id) + " because: " + refused);
+ if (const auto removed = RunRemove(c, request.app_id, false); !removed.empty())
+ return "The game could not be prepared again: " + removed;
+ PublishKeptBottles(c);
+ const auto left = c.repository.Snapshot();
+ if (std::any_of(left.begin(), left.end(),
+ [&](const rt::RuntimeInstall& record) { return record.app_id == request.app_id; }))
+ return "The game's old PS5 title is still being removed. Press Update again.";
+ return RunPrepare(c, request, awaiting);
+ }
const auto install_id = existing->install_id;
existing = c.records.Find(install_id);
if (!existing) return "The game's install record is missing.";
changed = true;
}
+ if (const auto unlinked = UnlinkDxvkConfig(*existing); !unlinked.empty()) return unlinked;
auto admission = c.installer->AdmissionDiagnostic(*existing);
if (admission != "ok") {
const auto repaired = c.installer->RepairBottle(*existing);
@@ -1740,6 +1888,7 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&
c.admission[existing->install_id] = admission;
PublishInstalls(c);
if (admission != "ok") return "The PS5 title still fails its start check: " + admission;
+ OpenGameFolders(c, *existing);
return changed ? std::string{} : "This game is already prepared.";
}
if (existing->install_path != request.install_path)
@@ -1858,7 +2007,10 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&
for (int steps = 0; steps < kMaxPreparationSteps && !Stopping(); ++steps) {
const auto current = c.records.Find(install_id);
if (!current) return "The preparation record disappeared.";
- if (current->state == rt::PreparationState::kReady) return {};
+ if (current->state == rt::PreparationState::kReady) {
+ OpenGameFolders(c, *current);
+ return {};
+ }
if (current->state != rt::PreparationState::kPreparing && current->state != rt::PreparationState::kRegistering)
return current->last_failure ? current->last_failure->message : "Preparation stopped.";
const auto before = current->journal ? current->journal->step : std::string{};
@@ -2127,10 +2279,13 @@ std::string RuntimeHost::RunMaintenance(Composition& c, std::uint32_t app, Runti
return "Shader cache cleared. Shaders compile again on the next start.";
}
case RuntimeMaintenance::kRepair: {
- if (const auto unwritable = EnsureWritable(record->install_path,
- WorkingFolder(record->launch_working_directory, record->launch_path, record->launch_in_install_root));
- !unwritable.empty())
+ // An owned publication with a kit that admits unowned folders fails the start check once
+ // the player opened the folder; it is published again as unowned, just below.
+ const bool unowned_upgrade = NeedsUnownedPublication(c, *record);
+ const auto working = WorkingFolder(record->launch_working_directory, record->launch_path, record->launch_in_install_root);
+ if (const auto unwritable = EnsureWritable(record->install_path, working); !unwritable.empty())
return unwritable;
+ if (const auto unlinked = UnlinkDxvkConfig(*record); !unlinked.empty()) return unlinked;
const auto repaired = c.installer->RepairBottle(*record);
const auto admission = c.installer->AdmissionDiagnostic(*record);
c.admission[record->install_id] = admission;
@@ -2139,13 +2294,15 @@ std::string RuntimeHost::RunMaintenance(Composition& c, std::uint32_t app, Runti
PublishInstalls(c, record->install_id);
if (repaired.state != rt::PackageActionState::kComplete) return "The bottle could not be repaired: " + repaired.message;
// A game whose folder moved fails the check until it is published again, just below.
- if (admission != "ok" && record->moved_from.empty()) return "The PS5 title still fails its start check: " + admission;
+ if (admission != "ok" && record->moved_from.empty() && !unowned_upgrade)
+ return "The PS5 title still fails its start check: " + admission;
if (auto refused = RepublishSettings(c, *record); !refused.empty()) return refused;
- if (!record->moved_from.empty())
+ if (!record->moved_from.empty() || unowned_upgrade)
if (const auto current = c.records.Find(record->install_id))
if (const auto checked = c.installer->AdmissionDiagnostic(*current); checked != "ok")
return "The PS5 title still fails its start check: " + checked;
*ok = true;
+ if (const auto current = c.records.Find(record->install_id)) OpenGameFolders(c, *current);
if (!c.installer->TitleCurrent(*record) || !c.installer->TitleMetadataCurrent(*record))
return "Repaired. The PS5 title also has an update: press Update on the game page.";
return "Repaired. The game's start files and settings are in place.";
@@ -2549,7 +2706,9 @@ void RuntimeHost::Run() {
if (!native.log) native.log = [this](const std::string& line) { Log(line); };
c.coordinator = std::make_unique<ps5::Ps5NativeCoordinator>(
c.records, *c.installer, c.registry, config_.homebrew_root, std::move(native));
- c.owner = std::make_unique<rt::SettingsPublicationOwner>(c.records, *c.installer, *c.coordinator);
+ c.owner = std::make_unique<rt::SettingsPublicationOwner>(
+ c.records, *c.installer, *c.coordinator,
+ c.kit && rt::KitCapabilitiesFromManifest(c.kit->capabilities, true).game_root_unowned);
c.service = std::make_unique<rt::RuntimeInstallService>(
c.records, *c.installer, *c.coordinator,
[&c](const rt::RuntimeInstall& record) {
@@ -2644,12 +2803,16 @@ void RuntimeHost::Run() {
}
// Games whose folder moved with the games root (0.5) start from Home only once their
// publication names the new folder: republished now, busy titles wait for Play.
+ // So are games published owned while the kit admits unowned folders (folders opened for
+ // mods). The Steam account is not known yet, so the emulator's files wait for Play.
for (const auto& record : c.repository.Snapshot()) {
- if (record.moved_from.empty() || record.state != rt::PreparationState::kReady) continue;
+ if (record.state != rt::PreparationState::kReady) continue;
+ const bool moved = !record.moved_from.empty();
+ if (!moved && !NeedsUnownedPublication(c, record)) continue;
const auto busy = c.kit ? MaintenanceRefusal(c, record) : std::string("no verified kit");
bool published = false;
- const auto refused = busy.empty() ? RepublishSettings(c, record, &published) : busy;
- Log("startup moved app=" + std::to_string(record.app_id) + " " +
+ const auto refused = busy.empty() ? RepublishSettings(c, record, &published, false) : busy;
+ Log(std::string(moved ? "startup moved app=" : "startup unowned app=") + std::to_string(record.app_id) + " " +
(published ? std::string("republished") : (busy.empty() ? "failed: " : "waits: ") + refused));
}
FinishGamesMove(c);
@@ -2662,7 +2825,7 @@ void RuntimeHost::Run() {
if (!saved || saved->revision <= record.settings_revision || !record.moved_from.empty() ||
!MaintenanceRefusal(c, record).empty()) continue;
bool published = false;
- const auto refused = RepublishSettings(c, record, &published);
+ const auto refused = RepublishSettings(c, record, &published, false);
if (published || !refused.empty())
Log("startup settings app=" + std::to_string(record.app_id) + " " + (refused.empty() ? "applied" : refused));
}
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index 04c959a..cbb59ff 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -351,8 +351,16 @@ class RuntimeHost {
// Steam files, then a journaled settings update (profile, dxvk.conf, registry). Call only
// while the title is stopped. Empty on success or when nothing changed; *published says
// whether an update ran. The title keeps the launch entry it was prepared with.
+ // A moved game, or an owned publication with a kit that admits unowned folders
+ // (NeedsUnownedPublication), is published again at its revision.
+ // steam_account_known false (at startup): the Steam emulator's files wait for Play.
+ // *prepare_again: refused for a reason only a new preparation gets past (recipe or settings).
std::string RepublishSettings(Composition& composition, const runtime::RuntimeInstall& record,
- bool* published = nullptr);
+ bool* published = nullptr, bool steam_account_known = true,
+ bool* prepare_again = nullptr);
+ // A Ready game published owned (schema 2, before 0.5 or by a kit before 0.10) while the kit
+ // admits unowned game folders: published again as unowned, so folders the player opened pass.
+ bool NeedsUnownedPublication(const Composition& composition, const runtime::RuntimeInstall& record);
// The 0.5 games move: rewrites the records and Cloud indexes under the old games root at startup,
// and marks the move done once no moved Ready game is left to republish.
void MoveGameRecords(Composition& composition);
@@ -364,7 +372,9 @@ class RuntimeHost {
std::filesystem::path SaveBackupRoot(const std::string& install_id) const;
// Puts the game's steam_api DLLs in the state its "Steam features" setting asks for. Call
// only while the game is stopped; empty on success, otherwise why not (for the player).
- std::string ApplySteamworks(Composition& composition, const runtime::RuntimeInstall& record);
+ // steam_account_known false: the emulator's files (which name the account) are left as they are.
+ std::string ApplySteamworks(Composition& composition, const runtime::RuntimeInstall& record,
+ bool steam_account_known = true);
// Empty while the kit on disk is the one admitted at startup; otherwise what to tell the player.
std::string KitReplaced(const Composition& composition) const;
// Makes an owned, world-writable folder from root down to working 0755 (dxvk.conf goes there).
@@ -373,6 +383,13 @@ class RuntimeHost {
// (relative to the root; empty: none) before anything is written; empty, or which can't be written.
// Call before any ManagedDirectory of the operation is opened.
std::string EnsureWritable(const std::string& install_path, const std::string& working);
+ // Once the game is published unowned (kit with game-root-unowned): opens what older Playdens
+ // tightened, the folders from the game root down to its working folder that the app user owns
+ // and that are 0755 become 0777, so FTP can write into them (mods). Folders of other users are
+ // left alone. Call after the publication, while none of its ManagedDirectory objects is open.
+ void OpenGameFolders(const Composition& composition, const runtime::RuntimeInstall& record);
+ // A dxvk.conf with more than one link fails the title's start check; it becomes a copy of its own.
+ std::string UnlinkDxvkConfig(const runtime::RuntimeInstall& record);
runtime::LaunchPreflight Preflight(Composition& composition, const runtime::RuntimeInstall& record);
runtime::LaunchEvidence Evidence(Composition& composition, const runtime::RuntimeInstall& record,
const std::string& session_id);
diff --git a/src/runtime/settings_publication.cpp b/src/runtime/settings_publication.cpp
index 8883843..8c252ca 100644
--- a/src/runtime/settings_publication.cpp
+++ b/src/runtime/settings_publication.cpp
@@ -47,6 +47,12 @@ bool OwnedGameDirectory(const struct stat& info, bool unowned) {
return S_ISDIR(info.st_mode) && (unowned || (info.st_uid == geteuid() &&
((info.st_mode & 07777) == 0700 || (info.st_mode & 07777) == 0755)));
}
+// The operation publishes its game folder unowned (metadata schema 3).
+bool PublishesUnowned(const SettingsPublicationOperation& o) {
+ PwTitlePublicationMetadata m{};
+ return pw_title_publication_metadata_parse(reinterpret_cast<const uint8_t*>(o.metadata_bytes.data()),
+ o.metadata_bytes.size(), &m) == PW_OK && m.game_root_unowned != 0;
+}
// Reads a regular file (never through a symbolic link) up to maximum bytes, and
// syncs it so what an apply builds on is durable. The file read is the one that
// was statted (same device, inode and size); owner, mode, link count and times
@@ -141,13 +147,34 @@ bool NamesMovedRoot(const GameRootMove* moved, const std::string& title_id, cons
const auto root = LiveGameRoot(title_id, prefix);
return root && *root == moved->from;
}
+// An owned publication (schema 2) that an unowned one replaces. The player may have opened the
+// game folder since (mods over FTP), which the owned rule refuses, so it is checked as a folder
+// moved onto itself, with the unowned rule (VerifyMovedPublication).
+bool OwnedReplacedByUnowned(const std::string& previous_metadata, bool unowned) {
+ PwTitlePublicationMetadata m{};
+ return unowned && !previous_metadata.empty() &&
+ pw_title_publication_metadata_parse(reinterpret_cast<const uint8_t*>(previous_metadata.data()),
+ previous_metadata.size(), &m) == PW_OK && m.game_root_unowned == 0;
+}
+GameRootMove InPlace(const RuntimeInstall& r) { return {r.install_path, r.install_path}; }
+}
+std::optional<bool> PublishedGameRootUnowned(const RuntimeInstall& r, const std::filesystem::path& prefix) {
+ if (!prefix.empty() && (!prefix.is_absolute() || prefix != prefix.lexically_normal())) return std::nullopt;
+ auto profiles = ManagedDirectory::Open(Map(prefix, r.data_root + "/library/profiles"), DirectoryPolicy::kPrivate);
+ auto bytes = profiles ? ReadPublicationFile(*profiles, ".playden-publication", 32768) : std::nullopt;
+ PwTitlePublicationMetadata m{};
+ if (!bytes || !bytes->present || pw_title_publication_metadata_parse(
+ reinterpret_cast<const uint8_t*>(bytes->bytes.data()), bytes->bytes.size(), &m) != PW_OK)
+ return std::nullopt;
+ return m.game_root_unowned != 0;
}
std::optional<GameRootMove> GameRootMoveOf(const RuntimeInstall& record) {
if (record.moved_from.empty() || record.moved_from == record.install_path) return std::nullopt;
return GameRootMove{record.moved_from, record.install_path};
}
PackageActionResult VerifyMovedPublication(const RuntimeInstall& r, const GameRootMove& move,
- const std::string& receipt_bytes, const std::string& metadata_bytes, const std::filesystem::path& prefix) {
+ const std::string& receipt_bytes, const std::string& metadata_bytes, const std::filesystem::path& prefix,
+ bool unowned) {
const auto refuse = [](const char* message) { return Failure("publication-moved", message); };
if (!prefix.empty() && (!prefix.is_absolute() || prefix != prefix.lexically_normal()))
return refuse("Invalid canonical namespace.");
@@ -194,7 +221,7 @@ PackageActionResult VerifyMovedPublication(const RuntimeInstall& r, const GameRo
const auto moved_working = RebaseInstallPath(working, move.from, move.to);
struct stat info{};
if (!moved_working || lstat(Map(prefix, *moved_working).c_str(), &info) != 0 ||
- !OwnedGameDirectory(info, m.game_root_unowned != 0))
+ !OwnedGameDirectory(info, unowned || m.game_root_unowned != 0))
return refuse("The moved game's working folder is missing at its new place.");
return {PackageActionState::kComplete, {}, {}};
}
@@ -241,10 +268,14 @@ PackageActionResult PublishSettingsOperation(const SettingsPublicationOperation&
Map(deps.host_namespace_prefix, "/data/homebrew/" + previous.install.title_id + "/game-launch.json"),
Map(deps.host_namespace_prefix, profile_root + ".playden-publication")};
// A journal left by a game folder that moved names the old folder, which no longer exists.
- result = deps.moved_root && previous.install.install_path == deps.moved_root->from
- ? VerifyMovedPublication(o.install, *deps.moved_root, previous.committed_receipt_bytes, previous.metadata_bytes,
- deps.host_namespace_prefix)
- : deps.verify_files(previous, previous_paths, lease->fd(), true);
+ if (deps.moved_root && previous.install.install_path == deps.moved_root->from)
+ result = VerifyMovedPublication(o.install, *deps.moved_root, previous.committed_receipt_bytes, previous.metadata_bytes,
+ deps.host_namespace_prefix, PublishesUnowned(o));
+ else if (OwnedReplacedByUnowned(previous.metadata_bytes, PublishesUnowned(o)))
+ result = VerifyMovedPublication(o.install, InPlace(o.install), previous.committed_receipt_bytes,
+ previous.metadata_bytes, deps.host_namespace_prefix, true);
+ else
+ result = deps.verify_files(previous, previous_paths, lease->fd(), true);
if (!Complete(result)) return result;
result = deps.authorize_retirement(previous, o); if (!Complete(result)) return result;
if (!ArchiveSettingsPublicationOperation(control, previous).ok() || !held())
@@ -570,7 +601,12 @@ PackageActionResult PreflightSettingsPublication(const SettingsPublicationOperat
// apply's leftovers (presets switched A -> B -> A, an interrupted first setup) are
// Playden's own files and are written over.
if (!initial && NamesMovedRoot(moved, o.install.title_id, prefix)) {
- auto checked = VerifyMovedPublication(o.install, *moved, o.previous_receipt_bytes, o.previous_metadata_bytes, prefix);
+ auto checked = VerifyMovedPublication(o.install, *moved, o.previous_receipt_bytes, o.previous_metadata_bytes, prefix,
+ desired.game_root_unowned != 0);
+ if (!Complete(checked)) return {PackageActionState::kFailed, "publication-preflight-previous", checked.message};
+ } else if (!initial && OwnedReplacedByUnowned(o.previous_metadata_bytes, desired.game_root_unowned != 0)) {
+ auto checked = VerifyMovedPublication(o.install, InPlace(o.install), o.previous_receipt_bytes, o.previous_metadata_bytes,
+ prefix, true);
if (!Complete(checked)) return {PackageActionState::kFailed, "publication-preflight-previous", checked.message};
} else if (!initial) {
const auto host = prefix.string(); PwTitlePublicationPlatform platform{};
@@ -620,7 +656,8 @@ PackageActionResult PreflightSettingsPublication(const SettingsPublicationOperat
}
Result<SettingsPublicationOperation> CaptureSettingsPublicationOperation(const RuntimeInstall& r,
const SettingsLaunchPlan& plan, const std::string& kit_id, const std::string& transaction,
- std::int64_t unix_time, int borrowed, const std::filesystem::path& prefix, const GameRootMove* moved) {
+ std::int64_t unix_time, int borrowed, const std::filesystem::path& prefix, const GameRootMove* moved,
+ bool unowned_game_roots) {
auto fail = [](const std::string& message) {
return Result<SettingsPublicationOperation>::Failure(StorageError::kInvalidData, message);
};
@@ -660,12 +697,17 @@ Result<SettingsPublicationOperation> CaptureSettingsPublicationOperation(const R
auto hash = [&](auto& target, const std::string& bytes) {
auto digest = HashArtifactBytes(bytes); return digest && bind(target, *digest);
};
- // A game folder on a drive that records no owner or permissions (exFAT) is
- // published as schema 3 so the kit's launch admission accepts it.
- const auto records_ownership = platform::RecordsOwnership(Map(prefix, working));
- if (!records_ownership) return fail("The game's working directory cannot be checked.");
- PwTitlePublicationMetadata m{}; m.schema_version = *records_ownership ? 2 : 3;
- m.game_root_unowned = *records_ownership ? 0 : 1; m.settings_revision = plan.settings_revision;
+ // Schema 3 (game_root_unowned) lets the kit's launch admission accept a game folder of any
+ // owner and mode: every folder when the kit can, else one on a drive that records no owner
+ // or permissions (exFAT).
+ bool unowned = unowned_game_roots;
+ if (!unowned) {
+ const auto records_ownership = platform::RecordsOwnership(Map(prefix, working));
+ if (!records_ownership) return fail("The game's working directory cannot be checked.");
+ unowned = !*records_ownership;
+ }
+ PwTitlePublicationMetadata m{}; m.schema_version = unowned ? 3 : 2;
+ m.game_root_unowned = unowned ? 1 : 0; m.settings_revision = plan.settings_revision;
if (!bind(m.install_id, r.install_id) || !bind(m.title_id, r.title_id) || !bind(m.data_root, r.data_root) ||
!bind(m.profile_id, plan.profile_id) || !bind(m.runtime_bundle_id, r.runtime_bundle_id) ||
!bind(m.recipe_id, plan.recipe_id) || !bind(m.recipe_version, plan.recipe_version) || !bind(m.kit_id, kit_id) ||
@@ -727,10 +769,15 @@ Result<SettingsPublicationOperation> CaptureSettingsPublicationOperation(const R
auto profiles = library->OpenChild("profiles", DirectoryPolicy::kPrivate);
auto prior = profiles ? ReadPublicationFile(*profiles, ".playden-publication", 32768) : std::nullopt;
if (prior && prior->present && NamesMovedRoot(moved, r.title_id, prefix)) {
- auto checked = VerifyMovedPublication(r, *moved, receipt.bytes, prior->bytes, prefix);
+ auto checked = VerifyMovedPublication(r, *moved, receipt.bytes, prior->bytes, prefix, unowned);
if (!Complete(checked) || pw_title_publication_parse(reinterpret_cast<const uint8_t*>(receipt.bytes.data()),
receipt.bytes.size(), &parsed) != PW_OK)
return fail("Before state is not the verified publication of the moved game folder: " + checked.message);
+ } else if (prior && prior->present && OwnedReplacedByUnowned(prior->bytes, unowned)) {
+ auto checked = VerifyMovedPublication(r, InPlace(r), receipt.bytes, prior->bytes, prefix, true);
+ if (!Complete(checked) || pw_title_publication_parse(reinterpret_cast<const uint8_t*>(receipt.bytes.data()),
+ receipt.bytes.size(), &parsed) != PW_OK)
+ return fail("Before state is not the verified publication of this game folder: " + checked.message);
} else if (pw_title_publication_parse(reinterpret_cast<const uint8_t*>(receipt.bytes.data()), receipt.bytes.size(), &parsed) != PW_OK ||
parsed.phase != PW_TITLE_PUBLICATION_COMMITTED || !prior || !prior->present ||
pw_title_publication_read_descriptor(("/data/homebrew/" + r.title_id + "/game-launch.json").c_str(), r.title_id.c_str(),
diff --git a/src/runtime/settings_publication.h b/src/runtime/settings_publication.h
index 9cfdf10..f71611d 100644
--- a/src/runtime/settings_publication.h
+++ b/src/runtime/settings_publication.h
@@ -37,8 +37,13 @@ std::optional<GameRootMove> GameRootMoveOf(const RuntimeInstall& record);
// The committed publication a moved game folder left, checked like the title checks it, except
// the game folder (descriptor game_root, profile paths, dxvk.path), which names move.from and is
// checked at move.to. Profile, catalog and metadata in the private data root are hash-checked.
+// With unowned (the publication replacing it is unowned), the folder may have any owner and mode.
PackageActionResult VerifyMovedPublication(const RuntimeInstall& record, const GameRootMove& move,
const std::string& receipt_bytes, const std::string& metadata_bytes,
+ const std::filesystem::path& host_namespace_prefix = {}, bool unowned = false);
+// Whether the game's committed publication (its .playden-publication) admits the game folder
+// unowned (metadata schema 3); nothing when there is none or it can't be read.
+std::optional<bool> PublishedGameRootUnowned(const RuntimeInstall& record,
const std::filesystem::path& host_namespace_prefix = {});
enum class PublicationStep {
@@ -110,7 +115,8 @@ PackageActionResult ApplyPendingPublicationFiles(const SettingsPublicationOperat
// prior committed complete set; live dxvk.conf and user.reg must equal their frozen
// before-snapshots. Leftover files at new destinations are not refused (the apply
// writes over them). Never writes.
-// With moved, a previous publication that names moved->from is checked with VerifyMovedPublication.
+// With moved, a previous publication that names moved->from is checked with VerifyMovedPublication;
+// so is an owned (schema 2) previous publication that an unowned one replaces, in place.
PackageActionResult PreflightSettingsPublication(const SettingsPublicationOperation& operation,
const PublicationPaths& paths, int borrowed_publisher_fd,
const std::filesystem::path& host_namespace_prefix = {}, const GameRootMove* moved = nullptr);
@@ -118,9 +124,12 @@ PackageActionResult PreflightSettingsPublication(const SettingsPublicationOperat
// snapshots. Caller independently approves reserved OWNER/package provenance,
// positively stopped activity and the borrowed exclusive lease. Control/lock
// already exist. Only immutable backup preparation may write; no live edits.
+// unowned_game_roots: the kit has the game-root-unowned capability, so every game folder is
+// published unowned (metadata schema 3): users may add or change files in it (mods).
+// Without it, only a folder on a drive that records no owners (exFAT) is.
Result<SettingsPublicationOperation> CaptureSettingsPublicationOperation(
const RuntimeInstall& record, const SettingsLaunchPlan& plan, const std::string& kit_id,
const std::string& transaction_id, std::int64_t registry_unix_time,
int borrowed_publisher_fd, const std::filesystem::path& host_namespace_prefix = {},
- const GameRootMove* moved = nullptr);
+ const GameRootMove* moved = nullptr, bool unowned_game_roots = false);
} // namespace playden::runtime
diff --git a/src/runtime/settings_publication_owner.cpp b/src/runtime/settings_publication_owner.cpp
index 0035073..808b7c3 100644
--- a/src/runtime/settings_publication_owner.cpp
+++ b/src/runtime/settings_publication_owner.cpp
@@ -40,16 +40,19 @@ PublicationPaths OperationPaths(const SettingsPublicationOperation& operation, c
map(profiles + ".playden-publication")};
}
// A Ready update publishes a newer revision, or the same one again when the game folder
-// moved (RuntimeInstall::moved_from): its publication must then name the new folder.
-bool UpdateRevisionAllowed(const RuntimeInstall& current, std::uint64_t requested) {
- return requested > current.settings_revision || (requested == current.settings_revision && !current.moved_from.empty());
+// moved (RuntimeInstall::moved_from): its publication must then name the new folder. With a
+// kit that admits unowned folders, an owned publication is also published again as unowned.
+bool UpdateRevisionAllowed(const RuntimeInstall& current, std::uint64_t requested, bool unowned_game_roots) {
+ return requested > current.settings_revision ||
+ (requested == current.settings_revision && (!current.moved_from.empty() || unowned_game_roots));
}
bool MatchingJournal(const RuntimeInstall& r, const SettingsPublicationOperation& o) {
return r.journal && r.journal->operation == "settings-publication" && r.journal->operation_id == o.transaction_id;
}
}
SettingsPublicationOwner::SettingsPublicationOwner(InstallRecordStore& records, PackageInstaller& package,
- NativeCoordinator& native) : records_(records), package_(package), native_(native) {}
+ NativeCoordinator& native, bool unowned_game_roots)
+ : records_(records), package_(package), native_(native), unowned_game_roots_(unowned_game_roots) {}
PackageActionResult SettingsPublicationOwner::Request(const SettingsPublicationRequest& request,
const std::filesystem::path& directory) {
std::string reason; auto expected = EncodeSettingsPublicationRequest(request, &reason);
@@ -57,7 +60,7 @@ PackageActionResult SettingsPublicationOwner::Request(const SettingsPublicationR
const bool update = current && current->state == PreparationState::kReady;
const bool armed = current && current->journal && current->journal->operation == "settings-request";
if (!expected || !current || !SameRuntimeInstallIdentity(*current, request.install) ||
- (update ? !UpdateRevisionAllowed(*current, request.plan.settings_revision) :
+ (update ? !UpdateRevisionAllowed(*current, request.plan.settings_revision, unowned_game_roots_) :
request.plan.settings_revision != current->settings_revision) ||
(update ? !ReadyCaptureAllowed(*current, request.transaction_id) :
current->state != PreparationState::kPreparing || !current->journal ||
@@ -107,7 +110,7 @@ PackageActionResult SettingsPublicationOwner::ResumeRequested(const RuntimeInsta
auto loaded = LoadSettingsPublicationRequest(directory, current->journal->operation_id);
if (loaded.state != PublicationRecoveryState::kValid || !loaded.request ||
!SameRuntimeInstallIdentity(loaded.request->install, *current) ||
- (current->state == PreparationState::kReady ? !UpdateRevisionAllowed(*current, loaded.request->plan.settings_revision) :
+ (current->state == PreparationState::kReady ? !UpdateRevisionAllowed(*current, loaded.request->plan.settings_revision, unowned_game_roots_) :
loaded.request->plan.settings_revision != current->settings_revision))
return Failure("publication-request-unavailable", "Requested plan is missing, altered or does not match OWNER; preserve all evidence.");
const auto& request = *loaded.request;
@@ -274,7 +277,7 @@ Result<SettingsPublicationOperation> SettingsPublicationOwner::Prepare(const Run
CommitLaunch(&snapshot, record);
const auto moved = GameRootMoveOf(*current);
auto captured = CaptureSettingsPublicationOperation(snapshot, plan, kit, transaction, time, lease->fd(), prefix,
- moved ? &*moved : nullptr);
+ moved ? &*moved : nullptr, unowned_game_roots_);
if (!captured.ok()) return captured;
if (!lease->Validate(*control, "publication.lock"))
return fail("The publication lock changed before the capture was saved.");
diff --git a/src/runtime/settings_publication_owner.h b/src/runtime/settings_publication_owner.h
index e692fc1..c7370f6 100644
--- a/src/runtime/settings_publication_owner.h
+++ b/src/runtime/settings_publication_owner.h
@@ -8,7 +8,10 @@ namespace playden::runtime {
enum class PublicationControlStep { kOwnerArmed, kDirectorySynced, kLockSynced, kOwnerPrepared };
class SettingsPublicationOwner {
public:
- SettingsPublicationOwner(InstallRecordStore& records, PackageInstaller& package, NativeCoordinator& native);
+ // unowned_game_roots: the admitted kit has game-root-unowned; captures publish every game
+ // folder unowned (CaptureSettingsPublicationOperation).
+ SettingsPublicationOwner(InstallRecordStore& records, PackageInstaller& package, NativeCoordinator& native,
+ bool unowned_game_roots = false);
// Persist the exact requested plan in the existing
// private OWNER request directory, then arm OWNER before control/capture.
// Pre-arm orphans never resume implicitly. Ready updates retain their current
@@ -45,5 +48,6 @@ class SettingsPublicationOwner {
InstallRecordStore& records_;
PackageInstaller& package_;
NativeCoordinator& native_;
+ bool unowned_game_roots_ = false;
};
} // namespace playden::runtime
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index db85dda..067b490 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -144,9 +144,16 @@ RuntimeKit SyntheticKit(const fs::path& kit, const std::string& eboot = "native"
ImmutableArtifactLocation::kStagedTitle, "win/wine/lib/core.prx"},
{"recipe", "steam-220-hl2-v1-1", *HashArtifactFile(kit / "recipes/hl2.json"),
ImmutableArtifactLocation::kKit, "recipes/hl2.json"}};
- admitted.capabilities = {"dxvk", "offline_bottle", "per_game_title", "wow64_i386"};
+ admitted.capabilities = {"dxvk", "game-root-unowned", "offline_bottle", "per_game_title", "wow64_i386"};
return admitted;
}
+// A kit before 0.10: game folders must be the app user's and 0700/0755, except on drives
+// that record no owners, which it can't start games from.
+RuntimeKit WithoutUnownedRoots(RuntimeKit kit) {
+ kit.capabilities.erase(std::remove(kit.capabilities.begin(), kit.capabilities.end(), "game-root-unowned"),
+ kit.capabilities.end());
+ return kit;
+}
// The same kit with one shell for every game: its own param.json names the template title.
RuntimeKit AnyTitleKit(const fs::path& kit) {
auto admitted = SyntheticKit(kit);
@@ -481,8 +488,11 @@ void PreparesExistingDownloadToReady() {
CHECK(Read(game / "bin/steam_api.dll") == "unchanged-original-dll");
CHECK(Read(game / "hl2/save/quick.sav") == "existing-player-save");
CHECK(!fs::exists(fixture.root / "data/homebrew/FAKE78001/games"));
+ // The game folder stays world-writable (mods over FTP): the kit admits it as it is.
struct stat game_info{};
- CHECK(stat(game.c_str(), &game_info) == 0 && (game_info.st_mode & 07777) == 0755);
+ CHECK(stat(game.c_str(), &game_info) == 0 && (game_info.st_mode & 07777) == 0777);
+ const auto metadata = Read(fixture.root / "data/playden/games/steam-220/library/profiles/.playden-publication");
+ CHECK(metadata.find("schema=3\n") != std::string::npos && metadata.find("game_root.unowned=1\n") != std::string::npos);
// The staged title is readable by ShadowMount but not writable by others.
struct stat title_info{};
for (const auto* relative : {"data/homebrew/FAKE78001", "data/homebrew/FAKE78001/sce_sys"})
@@ -617,10 +627,12 @@ void ResumesInterruptedCaptureFromSavedRequest(bool tamper_backup = false) {
const auto kit = SyntheticKit(fixture.root / "kit");
config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";
+ const auto staged = fixture.root / "data/homebrew/FAKE78001";
unsigned uuids = 0;
- // Called just before capture: the first attempt sees a world-writable folder.
- config.uuid = [&uuids, game]() -> std::optional<std::string> {
- if (++uuids == 1) CHECK(chmod(game.c_str(), 0777) == 0);
+ // Called just before capture: the first attempt sees a world-writable PS5 title folder,
+ // which the capture's preflight refuses (game folders may be anything).
+ config.uuid = [&uuids, staged]() -> std::optional<std::string> {
+ if (++uuids == 1) CHECK(chmod(staged.c_str(), 0777) == 0);
return std::string("00000000-0000-4000-8000-00000000000") + std::to_string(uuids);
};
config.unix_time = [] { return std::int64_t{1760000000}; };
@@ -632,6 +644,7 @@ void ResumesInterruptedCaptureFromSavedRequest(bool tamper_backup = false) {
const auto failed = WaitFor(host, [](const RuntimeSnapshot& s) { return !s.preparing_app && s.refusals.count(220); }, 60);
CHECK(failed.installs.size() == 1 && failed.installs[0].state != PreparationState::kReady);
CHECK(failed.installs[0].recovery_pending);
+ CHECK(chmod(staged.c_str(), 0755) == 0);
// The saved request the journal names is in use: never leftover, never removed.
CHECK(failed.leftover_requests == 0);
host.CleanUpRequests();
@@ -1352,22 +1365,23 @@ void MaintainsReadyTitle() {
return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");
};
auto kit = SyntheticKit(fixture.root / "kit");
- kit.capabilities = {"dxvk", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+ kit.capabilities = {"dxvk", "game-root-unowned", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
unsigned uuids = 0;
- bool loosen_next = false; // the next armed update's capture sees a world-writable game folder
+ bool loosen_next = false; // the next armed update's capture sees a world-writable PS5 title folder
const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";
+ const auto staged = fixture.root / "data/homebrew/FAKE78001";
config.uuid = [&uuids]() -> std::optional<std::string> {
++uuids; return std::string("00000000-0000-4000-8000-00000000000") + std::to_string(uuids);
};
// Logged once the update is armed and before its capture: the seam for an interruption.
unsigned full_inspections = 0, ownership_inspections = 0;
- config.log = [&loosen_next, game, &full_inspections, &ownership_inspections](const std::string& line) {
+ config.log = [&loosen_next, staged, &full_inspections, &ownership_inspections](const std::string& line) {
if (line.rfind("package inspect ownership ", 0) == 0) ++ownership_inspections;
else if (line.rfind("package inspect ", 0) == 0) ++full_inspections;
if (loosen_next && line.rfind("settings update request", 0) == 0 && line.find(" state=0 ") != std::string::npos) {
loosen_next = false;
- CHECK(chmod(game.c_str(), 0777) == 0);
+ CHECK(chmod(staged.c_str(), 0777) == 0);
}
};
std::int64_t now = 1760000000;
@@ -1453,7 +1467,7 @@ void MaintainsReadyTitle() {
host.Play(220);
result = WaitFor(host, [plays](const RuntimeSnapshot& s) { return s.plays_handled > plays; }, 30);
CHECK(result.play_refusals.count(220) && launches.empty());
- CHECK(chmod(game.c_str(), 0755) == 0);
+ CHECK(chmod(staged.c_str(), 0755) == 0);
host.Prepare(Hl2());
result = WaitFor(host, [](const RuntimeSnapshot& s) {
return !s.preparing_app && !s.installs.empty() && (!s.installs[0].recovery_pending || s.refusals.count(220));
@@ -1477,6 +1491,274 @@ void MaintainsReadyTitle() {
host.Shutdown();
}
+// #73: files a player adds or changes over FTP (a mod, a world-writable folder) are theirs.
+// A kit that admits unowned game folders gets the folder as it is: Play, a settings update
+// and Repair all work, and the added files and modes stay.
+void ModdedGameFolderStillPlays() {
+ Fixture fixture;
+ auto config = fixture.Config();
+ config.host_namespace_prefix = fixture.root;
+ config.package_paths.console_data_root = "/data";
+ config.package_paths.host_data_root = fixture.root / "data";
+ config.package_operations.hash_file = HashArtifactFile;
+ config.package_operations.hash_bytes = HashArtifactBytes;
+ config.package_operations.free_space_unverifiable = true;
+ config.package_operations.validate_bottle = [](const fs::path& bottle) {
+ return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");
+ };
+ auto kit = SyntheticKit(fixture.root / "kit");
+ kit.capabilities = {"dxvk", "game-root-unowned", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+ config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
+ unsigned uuids = 0;
+ config.uuid = [&uuids]() -> std::optional<std::string> {
+ ++uuids; return std::string("00000000-0000-4000-8000-00000000000") + std::to_string(uuids);
+ };
+ config.unix_time = [] { return std::int64_t{1760000000}; };
+ config.session_data_root = fixture.root / "data";
+ std::vector<std::string> launches;
+ config.launch_title = [&launches](const std::string& title, const std::vector<std::string>&) {
+ launches.push_back(title);
+ return TitleResult{true, 0, "launch"};
+ };
+ GameSettingsRecord saved;
+ config.settings_record = [&saved](std::uint32_t) -> std::optional<GameSettingsRecord> { return saved; };
+ config.as_root = [](const std::function<bool()>& work) { return work(); };
+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";
+ Write(game / "hl2.exe", "existing-game", 0644);
+ CHECK(chmod(game.c_str(), 0755) == 0); // prepared by an older Playden, which tightened it
+ const auto mode = [](const fs::path& path) {
+ struct stat info{};
+ CHECK(lstat(path.c_str(), &info) == 0);
+ return unsigned(info.st_mode & 07777);
+ };
+
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ CHECK(WaitFor(host, Started).kit_available);
+ host.Prepare(Hl2());
+ auto done = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && (s.refusals.count(220) || (!s.installs.empty() && s.installs[0].state == PreparationState::kReady));
+ }, 60);
+ CHECK(!done.refusals.count(220) && done.installs[0].state == PreparationState::kReady);
+
+ // The mod, as an FTP client leaves it: world-writable folders and files.
+ Write(game / "GInput.asi", "mod-plugin", 0666);
+ Write(game / "mods/GInput.ini", "mod-settings", 0666);
+ CHECK(chmod((game / "mods").c_str(), 0777) == 0);
+ CHECK(chmod(game.c_str(), 0777) == 0);
+ const auto mod_kept = [&] {
+ CHECK(Read(game / "GInput.asi") == "mod-plugin" && Read(game / "mods/GInput.ini") == "mod-settings");
+ CHECK(mode(game) == 0777 && mode(game / "mods") == 0777 && mode(game / "GInput.asi") == 0666);
+ CHECK(Read(game / "hl2.exe") == "existing-game");
+ };
+
+ const auto maintain = [&host](RuntimeMaintenance action) {
+ const auto before = host.Snapshot().maintenance_handled;
+ host.Maintain(220, action);
+ return WaitFor(host, [before](const RuntimeSnapshot& s) { return s.maintenance_handled > before; }, 60);
+ };
+ // A settings update republishes into the opened-up folder. One the app user can't write
+ // (root's 0755 after an FTP upload; 0555 stands in for it) is opened up first.
+ if (geteuid() != 0) CHECK(chmod(game.c_str(), 0555) == 0);
+ saved.revision = 1;
+ saved.overrides = {{"frame_limit", "30"}};
+ auto result = maintain(RuntimeMaintenance::kApplySettings);
+ if (!result.maintenance.at(220).ok) std::fprintf(stderr, "Apply refused: %s\n", result.maintenance.at(220).message.c_str());
+ CHECK(result.maintenance.at(220).ok && result.installs[0].settings_revision == 1);
+ CHECK(Read(game / "dxvk.conf").find("maxFrameRate = 30") != std::string::npos);
+ mod_kept();
+ // Repair passes the start check and keeps the mod.
+ result = maintain(RuntimeMaintenance::kRepair);
+ if (!result.maintenance.at(220).ok) std::fprintf(stderr, "Repair refused: %s\n", result.maintenance.at(220).message.c_str());
+ CHECK(result.maintenance.at(220).ok);
+ mod_kept();
+ // Prepare again (Update) is not refused for the folder either.
+ host.Prepare(Hl2());
+ done = WaitFor(host, [](const RuntimeSnapshot& s) { return !s.preparing_app && s.refusals.count(220); });
+ CHECK(done.refusals.at(220) == "This game is already prepared.");
+ mod_kept();
+ // A dxvk.conf hard-linked by hand fails the title's start check; Repair makes it a copy of its own.
+ const auto dxvk = Read(game / "dxvk.conf");
+ CHECK(link((game / "dxvk.conf").c_str(), (game / "dxvk-copy.conf").c_str()) == 0);
+ result = maintain(RuntimeMaintenance::kRepair);
+ if (!result.maintenance.at(220).ok) std::fprintf(stderr, "Repair refused: %s\n", result.maintenance.at(220).message.c_str());
+ CHECK(result.maintenance.at(220).ok);
+ struct stat linked{};
+ CHECK(lstat((game / "dxvk.conf").c_str(), &linked) == 0 && linked.st_nlink == 1);
+ CHECK(Read(game / "dxvk.conf") == dxvk && Read(game / "dxvk-copy.conf") == dxvk);
+ mod_kept();
+ // Play publishes newer settings first, then starts the game.
+ saved.revision = 2;
+ saved.overrides = {{"frame_limit", "60"}};
+ host.Play(220);
+ WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready; }, 30);
+ CHECK(host.Handoff() && launches.size() == 1);
+ CHECK(host.Snapshot().installs[0].settings_revision == 2);
+ CHECK(Read(game / "dxvk.conf").find("maxFrameRate = 60") != std::string::npos);
+ mod_kept();
+ host.Shutdown();
+}
+
+// A game an older Playden or kit published owned (schema 2), which the player then opened for a
+// mod. With a kit that admits unowned folders, each way back republishes it unowned: the
+// startup pass (route 0), or with the title busy at startup, Repair (1), a settings update (2),
+// Update (3) or Play (4). Owned 0755 folders that were tightened open up again (route 0), but
+// never while the publication stays owned (5: the republication is refused).
+void OwnedPublicationOpenedUpRecovers(int route) {
+ Fixture fixture;
+ auto config = fixture.Config();
+ config.host_namespace_prefix = fixture.root;
+ config.package_paths.console_data_root = "/data";
+ config.package_paths.host_data_root = fixture.root / "data";
+ config.package_operations.hash_file = HashArtifactFile;
+ config.package_operations.hash_bytes = HashArtifactBytes;
+ config.package_operations.free_space_unverifiable = true;
+ config.package_operations.validate_bottle = [](const fs::path& bottle) {
+ return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");
+ };
+ auto kit = SyntheticKit(fixture.root / "kit");
+ kit.capabilities = {"dxvk", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+ config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
+ unsigned uuids = 0;
+ config.uuid = [&uuids]() -> std::optional<std::string> {
+ char id[37]; std::snprintf(id, sizeof(id), "00000000-0000-4000-8000-%012u", ++uuids);
+ return std::string(id);
+ };
+ config.unix_time = [] { return std::int64_t{1760000000}; };
+ config.session_data_root = fixture.root / "data";
+ config.launch_title = [](const std::string&, const std::vector<std::string>&) { return TitleResult{true, 0, "launch"}; };
+ GameSettingsRecord saved;
+ config.settings_record = [&saved](std::uint32_t) -> std::optional<GameSettingsRecord> { return saved; };
+ std::vector<std::string> lines;
+ std::mutex lines_mutex;
+ config.log = [&](const std::string& line) { std::lock_guard<std::mutex> lock(lines_mutex); lines.push_back(line); };
+ const auto logged = [&](const std::string& prefix) {
+ std::lock_guard<std::mutex> lock(lines_mutex);
+ return std::any_of(lines.begin(), lines.end(), [&](const std::string& line) { return line.rfind(prefix, 0) == 0; });
+ };
+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";
+ Write(game / "hl2.exe", "existing-game", 0644);
+ CHECK(chmod(game.c_str(), 0777) == 0);
+ const auto metadata = fixture.root / "data/playden/games/steam-220/library/profiles/.playden-publication";
+ const auto mode = [](const fs::path& path) {
+ struct stat info{};
+ CHECK(lstat(path.c_str(), &info) == 0);
+ return unsigned(info.st_mode & 07777);
+ };
+ if (route == 5) saved.revision = 1;
+ {
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ CHECK(WaitFor(host, Started).kit_available);
+ host.Prepare(Hl2());
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && (s.refusals.count(220) || (!s.installs.empty() && s.installs[0].state == PreparationState::kReady));
+ }, 60);
+ CHECK(!done.refusals.count(220) && done.installs[0].state == PreparationState::kReady);
+ host.Shutdown();
+ }
+ CHECK(Read(metadata).find("schema=2\n") != std::string::npos && mode(game) == 0755);
+ Write(game / "GInput.asi", "mod-plugin", 0666);
+ if (route == 5) {
+ saved.revision = 0; // older than the title's: the republication is refused
+ kit.capabilities = {"dxvk", "game-root-unowned", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ WaitFor(host, Started);
+ CHECK(logged("startup unowned app=220 failed: "));
+ CHECK(Read(metadata).find("schema=2\n") != std::string::npos && mode(game) == 0755);
+ host.Shutdown();
+ return;
+ }
+ if (route != 0) CHECK(chmod(game.c_str(), 0777) == 0); // opened over FTP
+ kit.capabilities = {"dxvk", "game-root-unowned", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+ if (route != 0) fixture.activity->store(static_cast<int>(NativeActivity::kActive));
+
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ WaitFor(host, Started);
+ if (route == 0) {
+ CHECK(logged("startup unowned app=220 republished"));
+ } else {
+ CHECK(logged("startup unowned app=220 waits: "));
+ CHECK(Read(metadata).find("schema=2\n") != std::string::npos);
+ fixture.activity->store(static_cast<int>(NativeActivity::kStopped));
+ }
+ const auto maintain = [&host](RuntimeMaintenance action) {
+ const auto before = host.Snapshot().maintenance_handled;
+ host.Maintain(220, action);
+ return WaitFor(host, [before](const RuntimeSnapshot& s) { return s.maintenance_handled > before; }, 60).maintenance.at(220);
+ };
+ bool played = false;
+ if (route == 1 || route == 2) {
+ if (route == 2) { saved.revision = 1; saved.overrides = {{"frame_limit", "30"}}; }
+ const auto result = maintain(route == 1 ? RuntimeMaintenance::kRepair : RuntimeMaintenance::kApplySettings);
+ if (!result.ok) std::fprintf(stderr, "route %d refused: %s\n", route, result.message.c_str());
+ CHECK(result.ok);
+ } else if (route == 3) {
+ const auto before = host.Snapshot().prepares_handled;
+ host.Prepare(Hl2());
+ const auto done = WaitFor(host, [before](const RuntimeSnapshot& s) { return s.prepares_handled > before; }, 60);
+ if (done.refusals.count(220)) std::fprintf(stderr, "Update refused: %s\n", done.refusals.at(220).c_str());
+ CHECK(!done.refusals.count(220));
+ } else if (route == 4) {
+ host.Play(220);
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready || s.play_refusals.count(220); }, 30);
+ if (done.play_refusals.count(220)) std::fprintf(stderr, "Play refused: %s\n", done.play_refusals.at(220).c_str());
+ CHECK(done.handoff_ready && host.Handoff());
+ played = true;
+ }
+ const auto published = Read(metadata);
+ CHECK(published.find("schema=3\n") != std::string::npos && published.find("game_root.unowned=1\n") != std::string::npos);
+ CHECK(mode(game) == 0777 && Read(game / "GInput.asi") == "mod-plugin" && mode(game / "GInput.asi") == 0666);
+ if (!played) {
+ host.Play(220);
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready || s.play_refusals.count(220); }, 30);
+ if (done.play_refusals.count(220)) std::fprintf(stderr, "Play refused: %s\n", done.play_refusals.at(220).c_str());
+ CHECK(done.handoff_ready && host.Handoff());
+ }
+ host.Shutdown();
+}
+
+// A kit without game-root-unowned (before 0.10) keeps the old rule: an owned, world-writable
+// game folder is tightened to 0755 and published owned (metadata schema 2). A folder owned by
+// another user is refused; that needs root to set up, so it isn't tested here.
+void KitWithoutUnownedRootsKeepsTightening() {
+ Fixture fixture;
+ auto config = fixture.Config();
+ config.host_namespace_prefix = fixture.root;
+ config.package_paths.console_data_root = "/data";
+ config.package_paths.host_data_root = fixture.root / "data";
+ config.package_operations.hash_file = HashArtifactFile;
+ config.package_operations.hash_bytes = HashArtifactBytes;
+ config.package_operations.free_space_unverifiable = true;
+ config.package_operations.validate_bottle = [](const fs::path& bottle) {
+ return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");
+ };
+ const auto kit = WithoutUnownedRoots(SyntheticKit(fixture.root / "kit"));
+ config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
+ config.uuid = [] { return std::optional<std::string>("00000000-0000-4000-8000-000000000001"); };
+ config.unix_time = [] { return std::int64_t{1760000000}; };
+ const auto game = fixture.root / "data/homebrew/FAKE77031/games/220";
+ Write(game / "hl2.exe", "existing-game", 0644);
+ CHECK(chmod(game.c_str(), 0777) == 0);
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ CHECK(WaitFor(host, Started).kit_available);
+ host.Prepare(Hl2());
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && (s.refusals.count(220) ||
+ (!s.installs.empty() && s.installs[0].state == PreparationState::kReady));
+ }, 60);
+ if (done.refusals.count(220)) std::fprintf(stderr, "Prepare refused: %s\n", done.refusals.at(220).c_str());
+ CHECK(!done.refusals.count(220) && done.installs[0].state == PreparationState::kReady);
+ struct stat info{};
+ CHECK(stat(game.c_str(), &info) == 0 && (info.st_mode & 07777) == 0755);
+ const auto metadata = Read(fixture.root / "data/playden/games/steam-220/library/profiles/.playden-publication");
+ CHECK(metadata.find("schema=2\n") != std::string::npos && metadata.find("game_root.unowned") == std::string::npos);
+ host.Shutdown();
+}
+
// A kit respin while a settings update waits for recovery (#5): the title is still this
// install's, so Update first finishes the saved update, and the title only reports that
// it needs Update (not current) until a second Update refreshes it.
@@ -1825,11 +2107,7 @@ void PreparesGameOnUnownedDrive() {
config.package_operations.validate_bottle = [](const fs::path& bottle) {
return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");
};
- auto kit = SyntheticKit(fixture.root / "kit");
- if (capable) {
- kit.capabilities.push_back("game-root-unowned");
- std::sort(kit.capabilities.begin(), kit.capabilities.end());
- }
+ auto kit = capable ? SyntheticKit(fixture.root / "kit") : WithoutUnownedRoots(SyntheticKit(fixture.root / "kit"));
config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };
unsigned uuids = 0;
config.uuid = [&uuids]() -> std::optional<std::string> {
@@ -2019,6 +2297,8 @@ void PreparesProgramChosenInSettings() {
CHECK(Read(profile).find("working_directory = Z:\\data\\homebrew\\FAKE77031\\games\\1592280\\Elsewhere\n") !=
std::string::npos);
CHECK(applied.installs[0].launch_working_directory == "Elsewhere");
+ struct stat elsewhere{}; // an owned 0755 folder on the way to dxvk.conf opens for FTP
+ CHECK(stat((game / "Elsewhere").c_str(), &elsewhere) == 0 && (elsewhere.st_mode & 07777) == 0777);
// Another program from the folder: the profile and the install record both name it.
Write(game / "Other.exe", pe, 0644);
saved.overrides = {{"program", "Other.exe"}, {"architecture", "pe64"}};
@@ -2307,7 +2587,7 @@ void PrepareThenMoveGames(Fixture& fixture, const RuntimeHostConfig& config, Gam
Write(old_games / ".playden-saves/220/cloud-index.txt",
"version=1\naccount=a\nchange=7\ngame_root=/data/homebrew/FAKE77031/games/220\n"
"prefix_root=/data/playden/games/steam-220/library/prefixes/game\nrule\tg\t1\tsave\t*\tsave/\n"
- "file\tg\t3\t5\tsave/game_root=/data/homebrew/FAKE77031/games/220\n", 0644);
+ "file\tg\t3\t5\tsave/game_root=/data/homebrew/FAKE77031/games/220\n", 0666); // Cloud writes it under umask 0
fs::rename(old_games, fixture.root / "data/playden-games");
std::lock_guard<std::mutex> lock(move.mutex);
move.journal = std::make_pair(std::string(kOldGames), std::string(kNewGames));
@@ -2358,7 +2638,10 @@ void MigrationRewritesInstallPathsAndRepublishes() {
// No new registration: the title stays the one Home lists.
CHECK(fixture.registry_mutations == registrations);
// The Cloud index follows the game folder; the bottle (prefix_root) did not move.
- const auto index = Read(fixture.root / "data/playden-games/.playden-saves/220/cloud-index.txt");
+ const auto index_path = fixture.root / "data/playden-games/.playden-saves/220/cloud-index.txt";
+ const auto index = Read(index_path);
+ struct stat index_info{}; // the rewrite keeps the file's mode, whatever the umask
+ CHECK(stat(index_path.c_str(), &index_info) == 0 && (index_info.st_mode & 07777) == 0666);
CHECK(index == "version=1\naccount=a\nchange=7\ngame_root=/data/playden-games/220\n"
"prefix_root=/data/playden/games/steam-220/library/prefixes/game\nrule\tg\t1\tsave\t*\tsave/\n"
"file\tg\t3\t5\tsave/game_root=/data/homebrew/FAKE77031/games/220\n");
@@ -2376,6 +2659,138 @@ void MigrationRewritesInstallPathsAndRepublishes() {
again.Shutdown();
}
+// A game an older Playden prepared (owned publication, schema 2) and the player then opened up
+// over FTP (#73): with a kit that admits unowned folders, the move republishes it unowned.
+void MovedModdedGameRepublishesUnowned() {
+ Fixture fixture;
+ GamesMove move;
+ auto kit = SyntheticKit(fixture.root / "kit");
+ kit.capabilities = {"dxvk", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+ unsigned uuids = 0;
+ const auto config = MoveConfig(fixture, kit, &uuids, move);
+ PrepareThenMoveGames(fixture, config, move);
+ const auto profiles = fixture.root / "data/playden/games/steam-220/library/profiles";
+ CHECK(Read(profiles / ".playden-publication").find("schema=2\n") != std::string::npos);
+ const auto game = fixture.root / "data/playden-games/220";
+ Write(game / "GInput.asi", "mod-plugin", 0666);
+ CHECK(chmod(game.c_str(), 0777) == 0);
+ kit.capabilities = {"dxvk", "game-root-unowned", "offline_bottle", "per_game_title", kKitDxvkConfig, "wow64_i386"};
+
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ const auto started = WaitFor(host, Started);
+ CHECK(started.installs.size() == 1 && started.installs[0].state == PreparationState::kReady);
+ CHECK(started.installs[0].admission == "ok");
+ CHECK(move.Logged("startup moved app=220 republished") && move.Done() == 1);
+ CheckRepublishedAtNewRoot(fixture);
+ const auto metadata = Read(profiles / ".playden-publication");
+ CHECK(metadata.find("schema=3\n") != std::string::npos && metadata.find("game_root.unowned=1\n") != std::string::npos);
+ struct stat info{};
+ CHECK(stat(game.c_str(), &info) == 0 && (info.st_mode & 07777) == 0777 && Read(game / "GInput.asi") == "mod-plugin");
+ host.Play(220);
+ const auto played = WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready || s.play_refusals.count(220); }, 30);
+ if (played.play_refusals.count(220)) std::fprintf(stderr, "Play refused: %s\n", played.play_refusals.at(220).c_str());
+ CHECK(played.handoff_ready);
+ host.Shutdown();
+}
+
+// The startup republication runs before the Steam account is known: the emulator's files keep
+// the account Play wrote, and Play rewrites them.
+void MovedGameStartupKeepsSteamAccount() {
+ Fixture fixture;
+ GamesMove move;
+ const auto kit = SyntheticKit(fixture.root / "kit");
+ unsigned uuids = 0;
+ auto config = MoveConfig(fixture, kit, &uuids, move);
+ config.settings_record = [](std::uint32_t) -> std::optional<GameSettingsRecord> {
+ GameSettingsRecord saved; saved.revision = 1; return saved;
+ };
+ const auto old_games = fixture.root / "data/homebrew/FAKE77031/games";
+ std::string pe(0x80 + 26, '\0');
+ pe[0] = 'M'; pe[1] = 'Z'; pe[0x3c] = 0x40; pe[0x40] = 'P'; pe[0x41] = 'E';
+ pe[0x44] = 0x64; pe[0x45] = static_cast<char>(0x86); pe[0x40 + 24] = 0x0b; pe[0x40 + 25] = 0x02;
+ Write(old_games / "4242/Bin/Game.exe", pe, 0644);
+ Write(old_games / "4242/Bin/steam_api64.dll", pe + std::string("\0SteamUser021\0", 14), 0644);
+ RuntimePrepareRequest request{4242, std::string(kOldGames) + "/4242", "internal", "Example Game"};
+ request.launches = {{"", "", "bin\\game.exe", "", "-windowed"}};
+ {
+ RuntimeHost host(config);
+ host.SetSteamAccount("player", 76561198000000001ull);
+ CHECK(host.Start());
+ CHECK(WaitFor(host, Started).kit_available);
+ host.Prepare(request);
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) {
+ return !s.preparing_app && (s.refusals.count(4242) || (!s.installs.empty() && s.installs[0].state == PreparationState::kReady));
+ }, 60);
+ if (done.refusals.count(4242)) std::fprintf(stderr, "Prepare refused: %s\n", done.refusals.at(4242).c_str());
+ CHECK(!done.refusals.count(4242) && done.installs[0].state == PreparationState::kReady);
+ host.Shutdown();
+ }
+ const auto user_ini = [&] { return Read(fixture.root / "data/playden-games/4242/Bin/steam_settings/configs.user.ini"); };
+ fs::rename(old_games, fixture.root / "data/playden-games");
+ CHECK(user_ini().find("account_name=player\n") != std::string::npos);
+ {
+ std::lock_guard<std::mutex> lock(move.mutex);
+ move.journal = std::make_pair(std::string(kOldGames), std::string(kNewGames));
+ }
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ WaitFor(host, Started);
+ CHECK(move.Logged("startup moved app=4242 republished") && move.Done() == 1);
+ CHECK(user_ini().find("account_name=player\n") != std::string::npos);
+ CHECK(user_ini().find("account_steamid=76561198000000001\n") != std::string::npos);
+ CHECK(move.Logged("steamworks app=4242 mode=emulate waits"));
+ host.Shutdown();
+}
+
+// A moved game whose publication can't be redone (here its saved settings went back to an older
+// revision than the title's) would be stuck: Play says to press Update, and Update prepares it
+// again from its new folder, as Recreate bottle does, keeping its saves.
+void StuckMovedGamePreparesAgainOnUpdate() {
+ Fixture fixture;
+ GamesMove move;
+ const auto kit = SyntheticKit(fixture.root / "kit");
+ unsigned uuids = 0;
+ auto config = MoveConfig(fixture, kit, &uuids, move);
+ auto revision = std::make_shared<std::atomic<std::uint64_t>>(1);
+ config.settings_record = [revision](std::uint32_t) -> std::optional<GameSettingsRecord> {
+ GameSettingsRecord saved; saved.revision = revision->load(); saved.overrides = {{"resolution", "1280x720"}};
+ return saved;
+ };
+ config.removal_poll_interval = std::chrono::milliseconds(1);
+ config.unregister_title = [&fixture](const std::string&, const std::string&) {
+ fixture.registered = false; fixture.submitted = false;
+ return TitleRemoverResult{true, 0, "answered"};
+ };
+ PrepareThenMoveGames(fixture, config, move);
+ const auto save = fixture.root / "data/playden/games/steam-220/library/prefixes/game/drive_c/users/steamuser/save.dat";
+ Write(save, "player-save", 0600);
+ revision->store(0);
+
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ WaitFor(host, Started);
+ CHECK(move.Logged("startup moved app=220 failed: ") && move.Done() == 0);
+ host.Play(220);
+ const auto played = WaitFor(host, [](const RuntimeSnapshot& s) { return s.handoff_ready || s.play_refusals.count(220); }, 30);
+ CHECK(played.play_refusals.count(220) &&
+ played.play_refusals.at(220).find("Press Update on the game page") != std::string::npos);
+ const auto before = host.Snapshot().prepares_handled;
+ host.Prepare({220, std::string(kNewGames) + "/220", "internal", "Half-Life \"2\""});
+ const auto done = WaitFor(host, [before](const RuntimeSnapshot& s) { return s.prepares_handled > before; }, 60);
+ if (done.refusals.count(220)) std::fprintf(stderr, "Update refused: %s\n", done.refusals.at(220).c_str());
+ CHECK(!done.refusals.count(220));
+ CHECK(done.installs.size() == 1 && done.installs[0].state == PreparationState::kReady);
+ CHECK(move.Logged("prepare again app=220 because: ") && move.Done() == 1);
+ const auto records = Read(fixture.root / "data/runtime-state/installs.json");
+ CHECK(records.find(R"("install_path":"/data/playden-games/220")") != std::string::npos &&
+ records.find("moved_from") == std::string::npos);
+ CHECK(Read(save) == "player-save" && !fs::exists(fixture.root / "data/playden/games/steam-220.kept"));
+ const auto descriptor = Read(fixture.root / "data/homebrew" / done.installs[0].title_id / "game-launch.json");
+ CHECK(descriptor.find(R"("game_root":"/data/playden-games/220")") != std::string::npos);
+ host.Shutdown();
+}
+
// A moved game whose title was busy at startup is republished by Play first, which says so.
void PlayBeforeRepublishRepublishesFirst() {
Fixture fixture;
@@ -2585,6 +3000,9 @@ int main(int argc, char** argv) {
PlaysReadyTitleThroughHandoff();
ReplacedKitAsksForRestart();
MaintainsReadyTitle();
+ ModdedGameFolderStillPlays();
+ KitWithoutUnownedRootsKeepsTightening();
+ for (int route = 0; route <= 5; ++route) OwnedPublicationOpenedUpRecovers(route);
SettingsSavedDuringPrepareReachReadyTitle();
KitRespinKeepsWaitingSettingsUpdate();
RemovesTitleKeepingSaves();
@@ -2593,6 +3011,9 @@ int main(int argc, char** argv) {
ShippedRecipeRequirementsFollowTheKit(false);
ShippedRecipeRequirementsFollowTheKit(true);
MigrationRewritesInstallPathsAndRepublishes();
+ MovedModdedGameRepublishesUnowned();
+ MovedGameStartupKeepsSteamAccount();
+ StuckMovedGamePreparesAgainOnUpdate();
PlayBeforeRepublishRepublishesFirst();
MigrationSkipsRecordsOutsideOldPrefix();
RestartDuringRepublishResumes();