Play your Steam library's Windows games on a jailbroken PS5.
C++
Say which PhysX version a game is missing
Leonardo Lobatod2cf7b09a7c5
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex 45480c5..96f942a 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -1432,6 +1432,8 @@ void Controller::TickRuntime() {play_queued_.empty() && !sync_before_play_.count(id);if (const auto note = play_notes_.find(id); note != play_notes_.end() && !launching) game.play_detail = note->second;if (sync_before_play_.count(id)) game.play_status = "Checking saves…";+ if (const auto physx = snapshot.physx_needed.find(NumberIn(snapshot, id)); physx != snapshot.physx_needed.end())+ game.physx_needed = physx->second;// Play's own work before the launch (a game moved in 0.6 is republished first).if (const auto progress = snapshot.play_progress.find(NumberIn(snapshot, id)); progress != snapshot.play_progress.end()) {game.play_status = progress->second; game.can_play = false; game.can_prepare = false;diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cppindex b9edf19..0d8f0aa 100644--- a/src/homebrew/runtime_host.cpp+++ b/src/homebrew/runtime_host.cpp@@ -1002,6 +1002,20 @@ std::string RuntimeHost::InstallScriptsStep(const GameFiles& files) {Publish([&](RuntimeSnapshot& s) { s.play_progress.erase(number); });}if (redist.physx_missing) Log("redist app=" + std::to_string(record.runtime_number) + " physx needed, no package in the game folder");+ // Still without the engine the game was built for, and a package added to its folder would be found: say which.+ std::optional<std::string> physx_needed;+ if (redist.physx_searched)+ for (const auto& program : files.programs) {+ if (!rt::ProgramUsesPhysx(files.root.string(), program) || rt::PhysxEngineBeside(files.root.string(), program)) continue;+ const auto version = rt::PhysxVersionBeside(files.root.string(), program);+ if (!rt::BottleHasPhysxEngine(files.prefix, version)) physx_needed = version;+ break;+ }+ if (physx_needed) Log("redist app=" + std::to_string(number) + " physx engine missing version=" + (physx_needed->empty() ? "unknown" : *physx_needed));+ Publish([&](RuntimeSnapshot& s) {+ if (physx_needed) s.physx_needed[number] = *physx_needed;+ else s.physx_needed.erase(number);+ });// Names and reasons come from the game's files: one line each, whatever they hold.const auto field = [](std::string text) {if (text.size() > 240) text.resize(240);diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hppindex b3a604e..8a58434 100644--- a/src/homebrew/runtime_host.hpp+++ b/src/homebrew/runtime_host.hpp@@ -361,6 +361,8 @@ struct RuntimeSnapshot {// What Play does before the launch is requested, per runtime number, while it runs: a game whose// folder moved in Playden 0.6 is republished first (kPlayUpdatingForLayout).std::map<std::uint32_t, std::string> play_progress;+ // Games without the PhysX engine they need, by runtime number: the version, empty when it isn't known.+ std::map<std::uint32_t, std::string> physx_needed;// What the latest Play from Playden went ahead without, per runtime number (Microsoft's MFC that could not be// downloaded): Play still starts the game, and the player sees why it may stop.std::map<std::uint32_t, std::string> play_notices;diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex 23bd0f7..7d2620b 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -6998,6 +6998,9 @@ void Simulation::rebuild_view() {if (runtime && !runtime->play_work.empty()) {setup.value = runtime->play_work.substr(0, runtime->play_work.rfind("…"));setup.tone = "busy";+ } else if (runtime && runtime->physx_needed && status == "Ready") {+ setup.value = "Needs PhysX";+ setup.tone = "attention";}setup.enabled = false;if (runtime && runtime->queued && runtime->uninstall_status.empty()) {@@ -7017,6 +7020,11 @@ void Simulation::rebuild_view() {else if (status == "Removal incomplete") hint = "Removing " + game->title + " from the PS5 Home screen stopped partway.";else if (status == "Needs repair") hint = "Some of " + game->title + "'s setup files changed.";else if (status == "No kit") hint = "Playden needs its runtime kit to set up games.";+ else if (runtime && runtime->physx_needed) {+ const auto& version = *runtime->physx_needed;+ hint = version.empty() ? "This game needs PhysX. Add its installer to the game's _Redist folder, then press Play."+ : "This game needs PhysX " + version + ". Add its installer to the game's _Redist folder, then press Play.";+ }else if (runtime && runtime->setup_other_kit)hint = "Setup started with an earlier kit. Recreate bottle makes it again; saves and settings are kept.";else if (runtime && (status == "Needs recovery" || status == "Failed")) {@@ -7031,7 +7039,7 @@ void Simulation::rebuild_view() {}if (!hint.empty()) {auto& note = row("details-hint", RowKind::Status, hint, "");- note.tone = setup.tone;+ note.tone = runtime && runtime->physx_needed && setup.tone != "busy" ? "attention" : setup.tone;note.enabled = false;}// Waiting behind other games: move it to the front; the game being set up now finishes first.diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex eac16ff..bd3a031 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -236,6 +236,7 @@ struct LiveRuntimeGame {// How far the current copy or deletion is (0–1); absent when it cannot be measured.std::optional<float> progress;std::string play_work; // Play's own work before the launch, for Setup ("Installing PhysX…")+ std::optional<std::string> physx_needed; // the PhysX engine the bottle lacks: its version, empty when unknown// Prepared and waiting for the PS5 to register its title, which it does once Playden// quits: the game is ready to play from Home, and Play quits there.bool awaiting_registration = false;diff --git a/src/runtime/redist_install.cpp b/src/runtime/redist_install.cppindex 0b4b98f..012591c 100644--- a/src/runtime/redist_install.cpp+++ b/src/runtime/redist_install.cpp@@ -734,6 +734,81 @@ std::string ExtendPath(const std::string& current, const std::vector<std::stringreturn out;}+namespace {++// The name in folder that matches without regard to case, as Windows does; empty when there is none.+std::string NameIn(const std::filesystem::path& folder, const std::string& lower) {+ std::error_code error;+ for (std::filesystem::directory_iterator it(folder, error), end; !error && it != end; it.increment(error))+ if (Lower(it->path().filename().string()) == lower) return it->path().filename().string();+ return {};+}++// a.b.c of a file's version resource, read from the file's bytes; empty when it has none.+std::string FileVersion(const std::filesystem::path& path) {+ std::string data;+ if (!ReadFile(path, 32u * 1024u * 1024u, &data)) return {};+ static constexpr char kKey[] = "V\0S\0_\0V\0E\0R\0S\0I\0O\0N\0_\0I\0N\0F\0O\0";+ const auto key = data.find(std::string_view(kKey, sizeof(kKey) - 1));+ if (key == std::string::npos) return {};+ static constexpr char kSignature[] = "\xBD\x04\xEF\xFE";+ const auto signature = data.find(std::string_view(kSignature, 4), key);+ if (signature == std::string::npos || signature > key + 256 || data.size() < signature + 16) return {};+ const auto word = [&](std::size_t at) {+ return static_cast<unsigned>(static_cast<unsigned char>(data[at])) | static_cast<unsigned>(static_cast<unsigned char>(data[at + 1])) << 8;+ };+ // VS_FIXEDFILEINFO: signature, struct version, then the file version's two parts, each low word first.+ return std::to_string(word(signature + 10)) + "." + std::to_string(word(signature + 8)) + "." + std::to_string(word(signature + 14));+}++std::filesystem::path ProgramFolder(const std::string& game_root, const std::string& program) {+ return (std::filesystem::path(game_root) / program).parent_path();+}++} // namespace++std::string PhysxVersionBeside(const std::string& game_root, const std::string& program) {+ const auto folder = ProgramFolder(game_root, program);+ for (const auto* library : {"nxcooking.dll", "physxcooking.dll", "physxextensions.dll"}) {+ const auto name = NameIn(folder, library);+ if (name.empty()) continue;+ const auto version = FileVersion(folder / name);+ if (version.rfind("2.", 0) == 0) return version;+ }+ return {};+}++bool PhysxEngineBeside(const std::string& game_root, const std::string& program) {+ const auto folder = ProgramFolder(game_root, program);+ return !NameIn(folder, "physxcore.dll").empty() || !NameIn(folder, "physxlocal").empty();+}++bool BottleHasPhysxEngine(const std::string& prefix_dir, const std::string& version) {+ const auto drive = std::filesystem::path(prefix_dir) / "drive_c";+ const auto files = NameIn(drive, "program files (x86)");+ if (files.empty()) return false;+ // Walks down names without regard to case; empty when a part is missing.+ const auto below = [](std::filesystem::path at, std::initializer_list<const char*> parts) {+ for (const auto* part : parts) {+ const auto name = NameIn(at, part);+ if (name.empty()) return std::filesystem::path();+ at /= name;+ }+ return at;+ };+ for (const auto& engines : {below(drive / files, {"nvidia corporation", "physx", "engine"}), below(drive / files, {"ageia technologies"})}) {+ if (engines.empty()) continue;+ if (!version.empty()) {+ if (!below(engines, {("v" + version).c_str(), "physxcore.dll"}).empty()) return true;+ continue;+ }+ std::error_code error;+ for (std::filesystem::directory_iterator it(engines, error), end; !error && it != end; it.increment(error))+ if (!NameIn(it->path(), "physxcore.dll").empty()) return true;+ }+ return false;+}+bool RedistIsPhysx(const std::string& name) { return Lower(name).find("physx") != std::string::npos; }RedistInstallResult InstallRedistributables(const std::string& game_root, const std::string& install_dir,@@ -878,6 +953,7 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, construn("(no script)", RedistEntry{"PhysX", base + "\\" + windows, "", ""});}result.physx_missing = packages.empty();+ result.physx_searched = true;}return result;}diff --git a/src/runtime/redist_install.h b/src/runtime/redist_install.hindex f5cf2fa..bf70e34 100644--- a/src/runtime/redist_install.h+++ b/src/runtime/redist_install.h@@ -39,8 +39,20 @@ struct RedistOutcome {struct RedistInstallResult {std::vector<RedistOutcome> outcomes;bool physx_missing = false; // find_physx, and the game folder has no PhysX package+ bool physx_searched = false; // find_physx, and no script names PhysX: a package added to the folder would be found};+// The PhysX version ("2.8.1") a program was built for, from the file version of the SDK libraries beside it+// (NxCooking.dll, PhysXCooking.dll, PhysXExtensions.dll). Empty when none says. program is relative to game_root.+std::string PhysxVersionBeside(const std::string& game_root, const std::string& program);++// Whether the program can run on its own PhysX engine: PhysXCore.dll or a PhysXLocal folder beside it.+bool PhysxEngineBeside(const std::string& game_root, const std::string& program);++// Whether the bottle has that version's PhysX engine, where PhysX's packages install it (NVIDIA's or AGEIA's folder).+// With an empty version, any engine.+bool BottleHasPhysxEngine(const std::string& prefix_dir, const std::string& version);+// Whether a redistributable's name (an install script's entry) is PhysX's.bool RedistIsPhysx(const std::string& name);diff --git a/tests/homebrew_library_graphical_test.cpp b/tests/homebrew_library_graphical_test.cppindex d42ac39..c18500a 100644--- a/tests/homebrew_library_graphical_test.cpp+++ b/tests/homebrew_library_graphical_test.cpp@@ -233,6 +233,9 @@ int main(int argc,char** argv) {live.UpdateRuntime(RuntimeState::Ready, {ready});capture_live("details-play-disabled.png");{+ LiveRuntimeGame physx=ready; physx.can_play=true; physx.play_status.clear(); physx.physx_needed="2.8.1";+ live.UpdateRuntime(RuntimeState::Ready, {physx});+ capture_live("details-physx-needed.png");LiveRuntimeGame installing=ready; installing.can_play=false; installing.play_status=installing.play_work="Installing PhysX…"; installing.progress=0.27F;live.UpdateRuntime(RuntimeState::Ready, {installing});capture_live("details-installing-physx.png");diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cppindex 92c360e..19e45cd 100644--- a/tests/homebrew_library_model_test.cpp+++ b/tests/homebrew_library_model_test.cpp@@ -2627,6 +2627,25 @@ void live_play_does_the_next_useful_thing() {model.UpdateRuntime(RuntimeState::Ready, {preparing});check(find_row(model, "details-play")->value.empty() && find_row(model, "details-setup")->value == preparing.detail,"work without a step number is only named in Setup");+ {+ // Without the PhysX engine the game needs: one message, whatever the folder holds, and Play stays.+ LiveRuntimeGame physx; physx.game_id = SteamId(42); physx.status = "Ready"; physx.ready = physx.can_play = true;+ physx.physx_needed = "2.8.1";+ model.UpdateRuntime(RuntimeState::Ready, {physx});+ check(find_row(model, "details-hint") &&+ find_row(model, "details-hint")->title == "This game needs PhysX 2.8.1. Add its installer to the game's _Redist folder, then press Play.",+ "the hint names the PhysX version and how to add it");+ check(find_row(model, "details-play")->enabled, "the hint doesn't stop Play");+ check(find_row(model, "details-setup")->value == "Needs PhysX" && find_row(model, "details-setup")->tone == "attention",+ "Setup doesn't say Ready while the engine is missing");+ physx.physx_needed = "";+ model.UpdateRuntime(RuntimeState::Ready, {physx});+ check(find_row(model, "details-hint")->title == "This game needs PhysX. Add its installer to the game's _Redist folder, then press Play.",+ "without a known version the hint still says what to add");+ physx.physx_needed.reset();+ model.UpdateRuntime(RuntimeState::Ready, {physx});+ check(!has_row(model, "details-hint"), "with the engine there is no hint");+ }{// Play installing a component first: the button counts, Setup says what it installs.LiveRuntimeGame installing; installing.game_id = SteamId(42); installing.status = "Ready"; installing.ready = true;diff --git a/tests/runtime_redist_test.cpp b/tests/runtime_redist_test.cppindex 03168ec..37c290c 100644--- a/tests/runtime_redist_test.cpp+++ b/tests/runtime_redist_test.cpp@@ -477,14 +477,39 @@ void TestFoundPhysx() {WriteText(scripted / "_CommonRedist/PhysX-Other.msi", "broken");prefix = fresh_prefix("scripted-prefix");result = InstallRedistributables(scripted.string(), "Z:\\games\\3", prefix.string(), 1700000100, true);- CHECK(result.outcomes.size() == 1 && result.outcomes[0].detail == "_CommonRedist/Chosen.msi");+ CHECK(result.outcomes.size() == 1 && result.outcomes[0].detail == "_CommonRedist/Chosen.msi" && !result.physx_searched);++ // Which version a game was built for, and whether a bottle has it.+ {+ const auto versioned = base / "versioned";+ std::string resource("MZ", 2);+ for (const char value : std::string("VS_VERSION_INFO")) { resource += value; resource += '\0'; }+ resource += std::string(6, '\0');+ resource += std::string("\xBD\x04\xEF\xFE\x00\x00\x01\x00", 8); // signature, struct version+ resource += std::string("\x08\x00\x02\x00\x0F\x00\x01\x00", 8); // 2.8 and 1.15, low words first+ WriteText(versioned / "Binaries/NxCooking.dll", resource);+ WriteText(versioned / "Binaries/Game.exe", "MZ");+ CHECK(PhysxVersionBeside(versioned.string(), "Binaries/Game.exe") == "2.8.1");+ CHECK(!PhysxEngineBeside(versioned.string(), "Binaries/Game.exe"));+ WriteText(versioned / "Other/NxCooking.dll", "no version");+ CHECK(PhysxVersionBeside(versioned.string(), "Other/Game.exe").empty());+ std::filesystem::create_directories(versioned / "Local/PhysXLocal");+ CHECK(PhysxEngineBeside(versioned.string(), "Local/Game.exe"));+ const auto bottle = base / "engines";+ CHECK(!BottleHasPhysxEngine(bottle.string(), "2.8.1") && !BottleHasPhysxEngine(bottle.string(), ""));+ WriteText(bottle / "drive_c/Program Files (x86)/NVIDIA Corporation/PhysX/Engine/v2.7.2/PhysXCore.dll", "core");+ CHECK(!BottleHasPhysxEngine(bottle.string(), "2.8.1") && BottleHasPhysxEngine(bottle.string(), "2.7.2") &&+ BottleHasPhysxEngine(bottle.string(), ""));+ WriteText(bottle / "drive_c/Program Files (x86)/AGEIA Technologies/v2.8.1/PhysXCore.dll", "core");+ CHECK(BottleHasPhysxEngine(bottle.string(), "2.8.1"));+ }// Needed, and nothing to install.const auto bare = base / "bare";std::filesystem::create_directories(bare / "Binaries");prefix = fresh_prefix("bare-prefix");result = InstallRedistributables(bare.string(), "Z:\\games\\4", prefix.string(), 1700000100, true);- CHECK(result.outcomes.empty() && result.physx_missing);+ CHECK(result.outcomes.empty() && result.physx_missing && result.physx_searched);std::filesystem::remove_all(base);}