From 3727a61e5962c14b652dc55804b0d6906f1510f6 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:43:42 -0500 Subject: [PATCH 1/7] Launcher: coexist with other OptiScaler setups When a game folder already holds an OptiScaler setup from another source, the launcher no longer takes it over or deletes its files: - An OptiScaler that names WrongGPU is still another setup's; a file is WrongGPU's only by the install record's name and hash. - Repair and Update ask before switching another setup's OptiScaler that sits over WrongGPU's proxy; the OK covers exactly the files moved aside. - OptiScaler.ini is WrongGPU's only while its keys point at WrongGPU's files. - The uninstall removes a changed file only by a WrongGPU release's hash; the game's own FSR DLL is never taken away without its original. - Other setups' OptiScaler plugins keep WrongGPU's RR out of an RR game unless the player agrees to move them aside (backed up, put back on uninstall). - WrongGPU's files beside another mod's OptiScaler are left to that setup; leftovers recognise WrongGPU's RR plugin and the 0.6.0 release's hashes. - The game page reads clearly for a game with another upscaler mod, gives one finding per file, and Last run shows the RR plugin's "stays off" lines. - Test programs can refuse to start with a temp folder outside a configured root (WRONGGPU_TEST_TEMP_ROOT, empty by default: no check). Tests: coexist-core, launcher-core and wg-core cases; coexist_061_tests.py drives the launcher on made-up folder layouts. Fixes #23 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/CMakeLists.txt | 28 ++ clean/installer/README.md | 18 +- clean/installer/src/app/cli.cpp | 5 + clean/installer/src/app/launcher_ui.cpp | 10 +- clean/installer/src/app/launcher_window.h | 5 +- clean/installer/src/app/main.cpp | 6 + clean/installer/src/app/restore_main.cpp | 6 + clean/installer/src/app/ui_dump.cpp | 4 +- clean/installer/src/app/ui_game.cpp | 36 +- clean/installer/src/app/ui_library.cpp | 15 +- clean/installer/src/app/ui_words.cpp | 15 +- clean/installer/src/wg_core/coexist.cpp | 87 ++-- clean/installer/src/wg_core/coexist.h | 25 +- clean/installer/src/wg_core/detect.cpp | 19 +- clean/installer/src/wg_core/fingerprint.cpp | 12 +- clean/installer/src/wg_core/fingerprint.h | 4 +- clean/installer/src/wg_core/install.cpp | 59 ++- clean/installer/src/wg_core/install.h | 2 +- clean/installer/src/wg_core/known_releases.h | 6 + clean/installer/src/wg_core/launcher.cpp | 20 +- clean/installer/src/wg_core/launcher.h | 2 + clean/installer/src/wg_core/leftovers.cpp | 31 +- clean/installer/src/wg_core/leftovers.h | 12 + clean/installer/src/wg_core/logtail.cpp | 42 +- clean/installer/src/wg_core/logtail.h | 24 +- clean/installer/src/wg_core/record.cpp | 74 +++- clean/installer/src/wg_core/record.h | 10 +- clean/installer/src/wg_core/test_temp_guard.h | 68 +++ clean/installer/tests/coexist_061_tests.py | 416 ++++++++++++++++++ clean/installer/tests/coexist_fixtures.py | 18 + clean/installer/tests/coexist_tests.cpp | 197 +++++++++ clean/installer/tests/launcher_core_tests.cpp | 140 +++++- clean/installer/tests/run_coexist_tests.py | 2 + clean/installer/tests/run_installer_tests.py | 23 +- clean/installer/tests/wg_core_tests.cpp | 9 + clean/installer/tests/wizard_policy_tests.cpp | 2 + clean/installer/tools/make_known_releases.py | 15 +- 37 files changed, 1357 insertions(+), 110 deletions(-) create mode 100644 clean/installer/src/wg_core/test_temp_guard.h create mode 100644 clean/installer/tests/coexist_061_tests.py diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index d9c5f402..2d60bf35 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -198,6 +198,34 @@ add_test(NAME coexist-core COMMAND coexist-core-tests) if(WRONGGPU_TESTING) add_test(NAME wizard-policy COMMAND wizard-policy-tests) endif() +# 0.6.1: the test programs (and WrongGPU.exe / the restorer of a WRONGGPU_TESTING build) refuse to start when TMP or TEMP is +# outside this folder (src/wg_core/test_temp_guard.h; forward slashes); empty: no check. The temp-guard-* tests start them +# with a temp folder outside it (paths that cannot be created, so a broken guard writes nothing) and pass on the refusal. +set(WRONGGPU_TEST_TEMP_ROOT "" CACHE STRING "Test programs refuse to start when TMP/TEMP is outside this folder (empty: no check)") +if(WRONGGPU_TEST_TEMP_ROOT) + set(WG_GUARDED wg-core-tests launcher-core-tests coexist-core-tests) + if(WRONGGPU_TESTING) + list(APPEND WG_GUARDED wizard-policy-tests WrongGPU WrongGPU-Restore) + endif() + foreach(t IN LISTS WG_GUARDED) + target_compile_definitions(${t} PRIVATE WG_TEST_TEMP_ROOT="${WRONGGPU_TEST_TEMP_ROOT}") + endforeach() + set(WG_OUTSIDE "C:/wg-temp-guard|outside") + foreach(t wg-core-tests launcher-core-tests coexist-core-tests) + add_test(NAME temp-guard-outside-${t} COMMAND ${t}) + set_tests_properties(temp-guard-outside-${t} PROPERTIES ENVIRONMENT "TMP=${WG_OUTSIDE};TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TMP=") + endforeach() + add_test(NAME temp-guard-temp-only COMMAND coexist-core-tests) + set_tests_properties(temp-guard-temp-only PROPERTIES ENVIRONMENT "TMP=${WRONGGPU_TEST_TEMP_ROOT}/tmp/temp-guard-probe;TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TEMP=") + add_test(NAME temp-guard-prefix COMMAND coexist-core-tests) + set_tests_properties(temp-guard-prefix PROPERTIES ENVIRONMENT "TMP=${WRONGGPU_TEST_TEMP_ROOT}-probe|x;TEMP=${WRONGGPU_TEST_TEMP_ROOT}-probe|x" PASS_REGULAR_EXPRESSION "refused: TMP=") + if(WRONGGPU_TESTING) + add_test(NAME temp-guard-outside-wizard-policy-tests COMMAND wizard-policy-tests) + set_tests_properties(temp-guard-outside-wizard-policy-tests PROPERTIES ENVIRONMENT "TMP=${WG_OUTSIDE};TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TMP=") + add_test(NAME temp-guard-outside-launcher COMMAND WrongGPU version) # (a broken guard: the version verb, no window) + set_tests_properties(temp-guard-outside-launcher PROPERTIES ENVIRONMENT "TMP=${WG_OUTSIDE};TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TMP=") + endif() +endif() target_include_directories(WrongGPU PRIVATE ${GEN}) target_compile_definitions(WrongGPU PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION}) target_link_libraries(WrongGPU PRIVATE wg_ui wg_core wgc_core comctl32 shell32 ole32 oleaut32 uuid advapi32 user32 gdi32 gdiplus dwmapi uxtheme d2d1 d3d11 dxgi dwrite windowscodecs uiautomationcore) diff --git a/clean/installer/README.md b/clean/installer/README.md index afb7ddc1..ffcf3ba0 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -32,6 +32,11 @@ AMD's upscaler; on any other build the plugin changes nothing and WrongGPU stays `Dx12Upscaler=fsr31`, `FfxDx12SRPath` and `UpscalerIndex=0` stay as before. Uninstall removes the plugin, its folder when the install made it, and its files (`wronggpu-asi.log`, `wronggpu-asi.ini` in the OptiScaler folder), and puts the player's OptiScaler.ini back. Tests: `test_asi_plugin`. +Other setups' plugins (0.6.1, `ForeignPlugins`): `.asi` files in `plugins\`, `OptiScaler\plugins\` or `wronggpu-plugins\` that +the install record doesn't name with that hash. In a Ray Reconstruction game WrongGPU's RR stays out by default (they may +hook RR too; the result says so); with the player's OK (the window's question, `--switch-plugins`) they are moved aside +(backed up, put back on uninstall) and WrongGPU's RR goes in. Elsewhere they stay beside WrongGPU's plugin. +WrongGPU RR from another package at exactly `plugins\WrongGPU-RR.asi` is overwritten by the install's RR plugin (backed up by its copy entry, put back on uninstall); under any other name it stays. For 007 First Light (`007FirstLight.exe`) the installer also sets OptiScaler's `[Spoofing] DxgiFactoryWrapping=true`: with OptiScaler 0.9.5.4 the game does not start otherwise when WrongGPU is OptiScaler's FSR library (the list is @@ -227,11 +232,16 @@ With the defaults nothing of this section changes the installer. kept and the old renamed copy is removed; the other DLLs are restored as usual. - **Files that changed since the install** (uninstall and update alike). A file that is WrongGPU's own all the same is removed like the one the record names, and the game's original comes back: an FSR DLL with WrongGPU's version - resource (a newer build the player placed by hand), or another payload file named `wronggpu*`, such as - `wronggpu_runtime.dll` (not the settings file). Any other changed FSR DLL follows the rule for game updates above; - any other changed file is left in place. The game's original of an FSR DLL is never removed while WrongGPU's DLL is + resource (a newer build the player placed by hand), or another payload file whose hash is one of WrongGPU's releases + (`known_releases.h`) or of the embedded payload (0.6.1: never by a version resource, which another setup's build may + carry; not the settings file). Any other changed FSR DLL follows the rule for game updates above; any other changed + file is left in place with a warning (another setup's OptiScaler over the proxy is named as such). OptiScaler.ini is the + install's only while its keys point at WrongGPU's files; an uninstall that leaves an OptiScaler.ini naming WrongGPU's + files warns that its setup may need them. The game's original of an FSR DLL is never removed while WrongGPU's DLL is under the game's name: it comes back from the backup, or from its `*.wronggpu-original.dll` copy when the backup - is missing or damaged, checked against the hash in the record. + is missing or damaged, checked against the hash in the record. When neither is there (0.6.1), an uninstall leaves + WrongGPU's DLL under the game's name with a warning (verify the game's files in the store) and removes the rest; an + update or repair stops before anything changes, keeping the record and backup. - **Collect logs** (button, `/COLLECT`, or "Modify" in Apps & features): one .zip with WrongGPU's logs and crash notes, the install record, setup log, model source, system information (Windows, GPU, driver, HIP runtime, FSR DLL state, model state, where the output filter comes from, file hashes) and recent Windows crash / GPU-reset events. diff --git a/clean/installer/src/app/cli.cpp b/clean/installer/src/app/cli.cpp index e81fec60..f1e80d20 100644 --- a/clean/installer/src/app/cli.cpp +++ b/clean/installer/src/app/cli.cpp @@ -4,6 +4,8 @@ // status [game] one game or all: status, versions, last run, problems // install | repair | update (--opti=, --model=, --experimental, // --switch: replace the player's own OptiScaler / other upscaler mod (backed up), +// --switch-plugins: other setups' OptiScaler plugins aside (backed up) so WrongGPU's +// Ray Reconstruction goes in (without it an RR game installs without WrongGPU's RR), // --removeold: remove an older WrongGPU install first, --force: no GPU/HIP block, // --rr-config-fix=on|off: Borderlands 4 / Hogwarts Legacy's Engine.ini question answered) // uninstall | rollback | adopt (adopt --all: every 0.5.x install the scan finds) @@ -437,6 +439,7 @@ void EntryJson(Json& j, const GameEntry& e) { FindingsJson(j, e.coexist); j.Key("proxy_plan").Obj().S("name", e.proxyPlan.name).S("reason", e.proxyPlan.reason).B("untested", e.proxyPlan.untested).End(); if (!e.leftovers.empty()) { + if (e.leftoversOtherSetup) j.B("leftovers_other_setup", true); // 0.6.1: used by another mod's setup (left alone) j.Key("leftovers").Arr(); for (auto& l : e.leftovers) j.Obj().S("path", l.rel).S("sha256", l.sha).S("version", l.version).End(); j.End(); @@ -600,6 +603,7 @@ int Verb(const wstring& verb, const Args& a, Output& o) { if (!Game(a, o, exe, dir)) return o.code; if (NeedsElevation(dir)) { o.j.S("error", L"administrator permission is needed for " + dir); return EXIT_REFUSED; } OpRequest r; ParseOp(verb, r.op); r.exe = exe; r.dir = dir; + r.force = a.has(L"force"); // 0.6.1: files another mod's setup uses are left alone unless --force OpLogBegin(); Ui ui; ui.step = [](int, int, const wstring&) {}; ui.log = [](const wstring& s) { LogLine(g.ctx, s); }; const OpResult res = RunOp(g.ctx, r, ui); @@ -636,6 +640,7 @@ int Verb(const wstring& verb, const Args& a, Output& o) { r.optiPackage = op == Op::Install || op == Op::Update || op == Op::Repair ? OptiFor(a, gs) : (!a.get(L"opti").empty() ? a.get(L"opti") : gs.optiPackage); r.modelDll = a.get(L"model"); r.moveMods = a.has(L"switch") || a.has(L"movemods"); + r.movePlugins = a.has(L"switch-plugins") || a.has(L"moveplugins"); // 0.6.1: other setups' OptiScaler plugins aside (WrongGPU's RR then goes in) r.removeOld = a.has(L"removeold") || a.has(L"clean-leftovers"); r.experimental = a.has(L"experimental"); r.force = a.has(L"force"); diff --git a/clean/installer/src/app/launcher_ui.cpp b/clean/installer/src/app/launcher_ui.cpp index 26703ce3..bed3b484 100644 --- a/clean/installer/src/app/launcher_ui.cpp +++ b/clean/installer/src/app/launcher_ui.cpp @@ -809,6 +809,13 @@ bool PrepareOp(const GameEntry& e, Op op, OpRequest& r, bool* failed, bool* gone return false; r.moveMods = true; } + if (t.coexist.foreignPluginsBlockRr) { // 0.6.1: other setups' plugins may hook RR too; keeping them leaves WrongGPU's RR out + wstring list; for (auto& p : t.coexist.foreignPlugins) list += (list.empty() ? L"" : L", ") + p; + r.movePlugins = RunDialog(0, L"Move the other OptiScaler plugins aside?\n\n" + t.name + L" has other OptiScaler plugins (" + list + L"). They may hook " + L"Ray Reconstruction as WrongGPU's does, so WrongGPU's Ray Reconstruction goes in only if they are moved aside. They are backed " + L"up and put back when you uninstall WrongGPU. If you keep them, WrongGPU installs without its Ray Reconstruction.", + {{L"Move them aside", 1, false, false}, {L"Keep them", 0, true, false}}, 0) == 1; + } if (t.conflicts.oldFound()) { if (!Confirm(L"Remove the older WrongGPU install first?\n\nAn older WrongGPU (DLSS 4.5 AMD) install is in this game. The game's original files are put back exactly as they were.", 0, L"Remove it first", L"Cancel")) @@ -859,12 +866,13 @@ void OnLeftovers(const GameEntry& e, bool clean) { wstring names; for (auto& f : e.leftovers) names += (names.empty() ? L"" : L"\n") + f.rel + L" (WrongGPU " + f.version + L")"; for (;;) { // Show details: the files' names, then the question again - const int a = RunDialog(0, LeftoversText(e.name, e.leftovers, clean), LeftoversButtons(clean), 0); + const int a = RunDialog(0, LeftoversText(e.name, e.leftovers, clean, e.leftoversOtherSetup), LeftoversButtons(clean, e.leftoversOtherSetup), 0); if (a == 1) break; if (a != 2 || !v.live) return; Inform(L"Details\n\n" + names, 2); } OpRequest r; r.op = clean ? Op::CleanLeftovers : Op::AdoptLeftovers; r.exe = e.exe; r.dir = e.dir; + r.force = e.leftoversOtherSetup; // (0.6.1: the player chose "anyway" for another mod's setup's files) StartOp(r); } // An install the launcher does not manage yet (WrongGPU setup 0.5, no profile.ini, its own uninstall entry): adopted, diff --git a/clean/installer/src/app/launcher_window.h b/clean/installer/src/app/launcher_window.h index e62ac095..4c167a0b 100644 --- a/clean/installer/src/app/launcher_window.h +++ b/clean/installer/src/app/launcher_window.h @@ -87,8 +87,9 @@ void HandOverToInstalled(HANDLE& one, const wstring& installedExe, const wchar_t bool AnswerReplaceOffer(HANDLE& one, const wstring& installedExe, const wstring& have, const LauncherStartDecision& start); // ui_words.cpp: "Update WrongGPU to X?"; true: Not now, this copy runs (rc5) void RemoveDataAsked(); // ui_words.cpp: a portable copy's Settings > Remove data... (RemoveSharedData) void StartHealth(bool gpu); // the model data, the RR data and the graphics card read again (the status line, Settings) -wstring LeftoversText(const wstring& name, const std::vector& files, bool clean); // Clean up / Adopt's question -std::vector LeftoversButtons(bool clean); +// Clean up / Adopt's question; otherSetup (0.6.1): the files are used by another mod's setup (said, Cancel the default) +wstring LeftoversText(const wstring& name, const std::vector& files, bool clean, bool otherSetup = false); +std::vector LeftoversButtons(bool clean, bool otherSetup = false); // ui_dump.cpp ("WrongGPU.exe ui-dump") drives the window offscreen with these const float kDefaultW = 1180, kDefaultH = 724; // the window's first size (DIPs) extern bool firstRunBusy, focusFirstStop; // the first run's checks still running; the Library's first stop takes the focus next diff --git a/clean/installer/src/app/main.cpp b/clean/installer/src/app/main.cpp index 4790b72e..f231690c 100644 --- a/clean/installer/src/app/main.cpp +++ b/clean/installer/src/app/main.cpp @@ -95,6 +95,9 @@ using std::wstring; #include "wg_core/payload.h" #include "wg_core/record.h" #include "wg_core/rrprep.h" +#ifdef WRONGGPU_TESTING +#include "wg_core/test_temp_guard.h" +#endif namespace wg::app { @@ -202,6 +205,9 @@ using namespace wg; using namespace wg::app; int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, PWSTR, int) { +#ifdef WRONGGPU_TESTING + if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // test builds: never a temp folder outside the configured root +#endif { // release 0.6.0: the Ray Reconstruction helper (rrprep.h): this program copied under a game's program name, started by // the launcher with --rr-prepare ; nothing else of the launcher runs in it int hc = 0; LPWSTR* hv = CommandLineToArgvW(GetCommandLineW(), &hc); diff --git a/clean/installer/src/app/restore_main.cpp b/clean/installer/src/app/restore_main.cpp index 047b856d..1e488d18 100644 --- a/clean/installer/src/app/restore_main.cpp +++ b/clean/installer/src/app/restore_main.cpp @@ -18,6 +18,9 @@ #include "wg_core/launcher.h" #include "wg_core/logs.h" #include "wg_core/record.h" +#ifdef WRONGGPU_TESTING +#include "wg_core/test_temp_guard.h" +#endif #ifndef WRONGGPU_VERSION_STR #define WRONGGPU_VERSION_STR L"0.0.0" @@ -66,6 +69,9 @@ wstring PlainError(const SetupError& e) { } // namespace int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int) { +#ifdef WRONGGPU_TESTING + if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // test builds: never a temp folder outside the configured root +#endif SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32); static const EmbeddedData data{nullptr, 0, 0, L"", 0, L"", 0, WRONGGPU_VERSION_STR}; Context ctx; diff --git a/clean/installer/src/app/ui_dump.cpp b/clean/installer/src/app/ui_dump.cpp index 867da786..8b43c63b 100644 --- a/clean/installer/src/app/ui_dump.cpp +++ b/clean/installer/src/app/ui_dump.cpp @@ -83,7 +83,9 @@ wstring GameInfo(const GameEntry& e) { } if (!e.hasRecord && !e.proxyPlan.name.empty() && e.status != GameStatus::Refused && e.status != GameStatus::ForeignMod) t += L"OptiScaler would be installed as " + e.proxyPlan.name + L" (" + e.proxyPlan.reason + L")\r\n"; - if (!e.leftovers.empty()) t += L"Leftover WrongGPU files (matched to WrongGPU " + e.leftovers[0].version + L" by their hashes): Clean up removes only these; Adopt makes them an install\r\n"; + if (!e.leftovers.empty() && e.leftoversOtherSetup) // 0.6.1 + t += L"WrongGPU files (matched to WrongGPU " + e.leftovers[0].version + L" by their hashes) " + kLeftoversOtherSetup + L": left alone\r\n"; + else if (!e.leftovers.empty()) t += L"Leftover WrongGPU files (matched to WrongGPU " + e.leftovers[0].version + L" by their hashes): Clean up removes only these; Adopt makes them an install\r\n"; if (!v.fixture && !IsFile(e.exe)) t += L"The game's exe is gone (moved or uninstalled): Remove files deletes what WrongGPU left in the folder.\r\n"; return t; } diff --git a/clean/installer/src/app/ui_game.cpp b/clean/installer/src/app/ui_game.cpp index 469ef579..97eb0591 100644 --- a/clean/installer/src/app/ui_game.cpp +++ b/clean/installer/src/app/ui_game.cpp @@ -47,7 +47,7 @@ static bool RrNoEdition(const GameEntry& e) { return e.rrDirect && e.hasRecord & // WrongGPU's Ray Reconstruction takes RR in this game: its files are in, it is on, the RR data is ready, and this build can // run it there bool RrOn(const GameEntry& e) { return e.rrInstalled && e.rrEnabled && v.rrReady && !RrBlocked(e) && !RrNoEdition(e); } -bool RrAloneLastRun(const GameEntry& e) { return RrOn(e) && e.last.found && (e.last.rrOnly || e.last.rrUpscaled); } +bool RrAloneLastRun(const GameEntry& e) { return RrOn(e) && e.last.RrAlone(); } // (0.6.1: never a run whose guard kept WrongGPU RR off) static bool RrFailedRun(const LastRun& lr); // (the Last run section, r7 #2) wstring RrModeName(const wstring& mode) { return mode == L"exact" ? L"Exact" : mode == L"fast" ? L"Fast" : L"Accurate"; } @@ -456,6 +456,14 @@ FindingWords WordsOf(const Finding& f) { w.sub = L"It turns the game's graphics into Vulkan, and WrongGPU needs Windows' own Direct3D 12."; break; case Tool::AsiLoader: w.sub = L"It stays. WrongGPU keeps its plugin in a folder of its own, so it starts once."; break; + case Tool::OtherPlugin: // 0.6.1: another setup's plugins beside OptiScaler + w.name = f.files.size() == 1 ? L"Another OptiScaler plugin" : L"Other OptiScaler plugins"; + w.sub = f.decision == Decision::Warn ? L"It may hook Ray Reconstruction too, so WrongGPU's Ray Reconstruction stays out unless you move them aside when you install." + : L"It stays. WrongGPU's plugin goes beside it."; + break; + case Tool::WrongGPU: // 0.6.1 (gap 4): WrongGPU's RR plugin placed by another package (it exports WrongGPU RR's marker) + if (f.what == L"WrongGPU RR (from another package)") w.sub = L"It stays. WrongGPU never moves its own Ray Reconstruction plugin aside."; + break; case Tool::Cet: case Tool::Red4ext: case Tool::Ue4ss: w.sub = L"It stays. WrongGPU doesn't touch it."; break; case Tool::HipRuntime: w.name = L"Another HIP tool"; w.sub = L"Keep Runs on at Auto or Direct3D 12 so the two don't clash."; break; case Tool::NrOnAmd: w.name = L"Another upscaler mod"; w.sub = L"WrongGPU doesn't install next to it and doesn't touch it."; break; @@ -1832,6 +1840,8 @@ static wstring RunWarning(const wstring& kind, const wstring& text, bool footSay if (kind == L"foreign-vtable") return L"An overlay or another mod (ReShade, Special K) took over some frames, so they used AMD FSR."; if (kind == L"xess-no-depth") return L"With XeSS chosen in the game, Model M gets less from the game and may look worse. Choose DLSS or FSR in the game's settings."; if (kind == L"no-depth") return L"The game gives the upscaler less than it needs, so Model M may look worse."; + // 0.6.1: the RR plugin's guard line itself (another Ray Reconstruction plugin, a second copy of WrongGPU RR, hooks replaced) + if (kind == L"rr-guard") return L"Ray Reconstruction: " + text + L"."; (void)text; // a kind this launcher does not know: the core's own sentence stays behind Show, with the log's lines return L"WrongGPU noted a warning in this run. Select Show to read it."; } @@ -1883,6 +1893,14 @@ static float LastRunSection(Gfx& gx, float x, float y, float w) { auto times = [](const wstring& s) { wstring o; for (wchar_t ch : s) o += ch == L'x' ? wstring(L"\u202f\u00d7\u202f") : wstring(1, ch); return o; }; // the run known from the RR log alone (r4 #1: Borderlands 4, Hogwarts Legacy and RE Requiem run Ray Reconstruction only, and // the front end logs nothing there): the Denoiser row leads, with its mode and cost, then the size; no upscaler rows + if (lr.rrGuardOff) { // 0.6.1: a session whose guard kept WrongGPU RR off: its line says why + KvOpt dn; + dn.sub = RunWarning(L"rr-guard", lr.rrGuard, false); + yy += KvRow(gx, x, yy, w, true, L"Denoiser", L"WrongGPU RR stayed off", dn); + yy += ActRow(gx, x, yy, w, false, false, ID_G_LOG, L"Open log", ic::external, Rec()); + yy += CollectRow(gx, x, yy, w); + return yy - top; + } if (lr.rrOnly) { KvOpt dn; wstring m = lr.rrMode.empty() ? wstring() : RrModeName(lr.rrMode); @@ -1935,7 +1953,8 @@ static float LastRunSection(Gfx& gx, float x, float y, float w) { // the RR data gone since that run: the page's Ray Reconstruction line says so, and this says it too if (!v.rrReady) m += (m.empty() ? L"" : L"\n") + wstring(L"Its data is missing now, so the next run uses the game's own denoiser."); dn.sub = m; - } else if (lr.rrFound) dn.sub = L"The game didn't ask for it in this run."; // the RR plugin ran, the game never made an instance + } else if (!lr.rrGuard.empty()) dn.sub = L"WrongGPU RR stayed off in this run (its reason is below)."; // 0.6.1: the RR plugin's guard + else if (lr.rrFound) dn.sub = L"The game didn't ask for it in this run."; // the RR plugin ran, the game never made an instance yy += KvRow(gx, x, yy, w, false, L"Denoiser", lr.rrUsed ? L"Ray Reconstruction" : L"Not used", dn); } if (!lr.renderSize.empty() && !lr.outputSize.empty()) yy += KvRow(gx, x, yy, w, false, L"Size", times(lr.renderSize) + L" \u2192 " + times(lr.outputSize)); @@ -2004,7 +2023,9 @@ static wstring StaysOutWhy(const GameEntry& e, wstring* tip) { // the status line's own lead-in ("Other upscaler mod: X", "Other upscaler mod (X): not touched"): the mod's name if (e.status == GameStatus::ForeignMod && why.rfind(L"Other upscaler mod: ", 0) == 0) why = why.substr(20); else if (e.status == GameStatus::ForeignMod && why.rfind(L"Other upscaler mod (", 0) == 0 && why.find(L')') != wstring::npos) why = why.substr(20, why.find(L')') - 20); - // the headline says another mod is here: the card names it and says why (not the headline again) + // the headline says another mod is here: the card names it and says why (not the headline again). 0.6.1: the mod that is + // never named ("Other upscaler mod: not touched") is "Another upscaler mod", not the status's last words + if (e.status == GameStatus::ForeignMod && (why.empty() || why == L"not touched" || why == L"Not touched")) why = L"Another upscaler mod"; if (e.status == GameStatus::ForeignMod) why = why + L" is in this game. WrongGPU stays out so the two don't fight over the upscaler."; else why += why.empty() || why.back() == L'.' ? L"" : L"."; return why; @@ -2058,10 +2079,13 @@ static float FolderSection(Gfx& gx, float x, float y, float w) { wstring ver; for (size_t k = 0; k < vers.size(); ++k) ver += (k == 0 ? L"" : k + 1 == vers.size() ? L" and " : L", ") + vers[k]; const size_t n = e.leftovers.size(); - const wstring t = n == 1 ? L"A file from WrongGPU " + ver + L" is here that the launcher didn't install. Clean up removes only it; Adopt lets the launcher manage it." - : std::to_wstring(n) + L" files from WrongGPU " + ver + L" are here that the launcher didn't install. Clean up removes only these; Adopt lets the launcher manage them."; + const wstring t = e.leftoversOtherSetup // 0.6.1: another mod's setup uses them (an OptiScaler WrongGPU didn't install is next to them) + ? (n == 1 ? L"A file from WrongGPU " + ver + L" is here that another mod's setup uses. WrongGPU leaves it alone; installing backs it up if it replaces it." + : std::to_wstring(n) + L" files from WrongGPU " + ver + L" are here that another mod's setup uses. WrongGPU leaves them alone; installing backs up any it replaces.") + : n == 1 ? L"A file from WrongGPU " + ver + L" is here that the launcher didn't install. Clean up removes only it; Adopt lets the launcher manage it." + : std::to_wstring(n) + L" files from WrongGPU " + ver + L" are here that the launcher didn't install. Clean up removes only these; Adopt lets the launcher manage them."; const float rowY = yy; - note(t, pal.amber); + note(t, e.leftoversOtherSetup ? pal.greyDot : pal.amber); AddHit(ID_G_FOUND, Rc{x, rowY, w, yy - rowY}, R_TEXT, t + L" Files: " + names, true, -1, L"", false); v.tips[ID_G_FOUND] = (n == 1 ? L"File: " : L"Files: ") + names; } diff --git a/clean/installer/src/app/ui_library.cpp b/clean/installer/src/app/ui_library.cpp index 3699f349..4c00e15d 100644 --- a/clean/installer/src/app/ui_library.cpp +++ b/clean/installer/src/app/ui_library.cpp @@ -308,6 +308,7 @@ static wstring LockupStatus(const GameEntry& e) { t += L" Last run " + When(e.last.when) + L": " + noRrFrame; else if (e.last.found && e.last.ready) t += L" Last run " + When(e.last.when) + on + (rrFailed ? L"; " + noRrFrame : wstring(L".")); else if (e.last.found && e.last.upscaler == L"amd") t += L" Last run " + When(e.last.when) + L" with AMD FSR" + (rrFailed ? L"; " + noRrFrame : wstring(L".")); + else if (e.last.found && e.last.rrGuardOff) t += L" Last run " + When(e.last.when) + L": WrongGPU RR stayed off."; // 0.6.1: its guard (the page says why) else if (!e.last.found) t += L" Not played yet."; // the lockup's own words return t; } @@ -1260,7 +1261,7 @@ static float FeatureBanner(Gfx& gx, float x0, float y, float cw, float h, int in // Clean up: their entries are not read yet, BusyWhy says so); Play and the games' pages work. A game that was running // is listed as it was before it ran. static const wchar_t kListHead[] = L"wronggpu-library-list 2"; // 2: the flags carry rrDirect and optiEdition (a list of 1 is not read) -constexpr size_t kListFields = 23; +constexpr size_t kListFields = 24; // (0.6.1: the last run's guard line; a list of 23 fields, before it, is read too) static wstring ListPath() { return gl.paths.dataDir.empty() ? wstring() : Join(gl.paths.dataDir, L"library-list.txt"); } void SaveLibrarySnapshot() { @@ -1279,11 +1280,10 @@ void SaveLibrarySnapshot() { const wstring flags = {bit(e.hasRecord), bit(e.recordV1), bit(e.perGameEntry), bit(e.hosted), bit(e.adoptable), bit(e.repairSuggested), bit(e.exeFound), bit(e.hasPrevious), bit(e.rrUses), bit(e.rrInstalled), bit(e.rrEnabled), bit(e.rrPathTracingOnly), bit(e.needsFound), bit(e.rrDirect), bit(e.optiEdition)}; - const wstring lastFlags = {bit(e.last.found), bit(e.last.ready), bit(e.last.optiPlugin), bit(e.last.upscaled), bit(e.last.rrOnly), - bit(e.last.rrUpscaled)}; // (r4 #1, r6 #1) + const wstring lastFlags = LastRunCacheFlags(e.last); // (r4 #1, r6 #1; 0.6.1: rrGuardOff, and its line in the last field) const wstring f[kListFields] = {e.name, e.exe, e.dir, e.source, e.appid, std::to_wstring((int)e.status), e.statusText, e.installedVersion, flags, e.previous, e.proxy, e.rrWhy, e.rrMode, e.needs, e.needsWhy, e.needsPage, e.needsGame, problems, - e.last.when, e.last.upscaler, e.last.executor, e.last.process, lastFlags}; + e.last.when, e.last.upscaler, e.last.executor, e.last.process, lastFlags, e.last.rrGuard}; for (size_t k = 0; k < kListFields; ++k) out += (k ? L"\t" : L"") + (k == 17 ? f[k] : field(f[k])); out += L"\n"; } @@ -1312,7 +1312,7 @@ bool LoadLibrarySnapshot() { std::vector games; for (size_t i = 1; i < lines.size() && games.size() < (size_t)kTileSpan; ++i) { const std::vector f = split(lines[i], L'\t'); - if (f.size() != kListFields || f[0].empty() || f[8].size() != 15 || (f[22].size() != 3 && f[22].size() != 5 && f[22].size() != 6)) continue; // (3: before r4; 5: before r6) + if ((f.size() != kListFields && f.size() != kListFields - 1) || f[0].empty() || f[8].size() != 15) continue; GameEntry e; e.name = f[0]; e.exe = f[1]; e.dir = f[2]; e.source = f[3]; e.appid = f[4]; const int st = _wtoi(f[5].c_str()); @@ -1328,9 +1328,8 @@ bool LoadLibrarySnapshot() { e.needs = f[13]; e.needsWhy = f[14]; e.needsPage = f[15]; e.needsGame = f[16]; if (!f[17].empty()) e.problems = split(f[17], (wchar_t)0x1f); e.last.when = f[18]; e.last.upscaler = f[19]; e.last.executor = f[20]; e.last.process = f[21]; - e.last.found = f[22][0] == L'1'; e.last.ready = f[22][1] == L'1'; e.last.optiPlugin = f[22][2] == L'1'; - if (f[22].size() >= 5) { e.last.upscaled = f[22][3] == L'1'; e.last.rrOnly = f[22][4] == L'1'; } - if (f[22].size() >= 6) e.last.rrUpscaled = f[22][5] == L'1'; + if (!ReadLastRunCacheFlags(f[22], e.last)) continue; // (3, 5, 6 or 7 flags: logtail.h) + if (f.size() == kListFields) e.last.rrGuard = f[23]; // 0.6.1: the RR plugin's guard line (the page's Last run and the banner from the start) if (e.status == GameStatus::Running) { // not running any more, most likely: as it was before it ran e.status = !e.hasRecord ? GameStatus::Eligible : !e.problems.empty() ? GameStatus::NeedsRepair : GameStatus::Installed; e.statusText.clear(); diff --git a/clean/installer/src/app/ui_words.cpp b/clean/installer/src/app/ui_words.cpp index 1700dc81..58aa8afa 100644 --- a/clean/installer/src/app/ui_words.cpp +++ b/clean/installer/src/app/ui_words.cpp @@ -327,17 +327,22 @@ wstring PlainTaskCause(const wstring& raw, int what) { // ---- the install's own questions and results (moved from launcher_ui.cpp, which uses them) ---- // Clean up / Adopt's question: what the files are in words; their names wait behind Show details (as on the game page, // where they are the tooltip) -wstring LeftoversText(const wstring& name, const std::vector& files, bool clean) { +wstring LeftoversText(const wstring& name, const std::vector& files, bool clean, bool otherSetup) { std::vector vers; for (auto& f : files) if (std::find(vers.begin(), vers.end(), f.version) == vers.end()) vers.push_back(f.version); wstring ver; for (size_t k = 0; k < vers.size(); ++k) ver += (k == 0 ? L"" : k + 1 == vers.size() ? L" and " : L", ") + vers[k]; const wstring what = (files.size() == 1 ? wstring(L"1 file") : std::to_wstring(files.size()) + L" files") + L" from WrongGPU " + ver + L" that the launcher didn't install."; - return clean ? L"Remove the leftover WrongGPU files from " + name + L"?\n\n" + what + L" Only these files are removed." - : L"Adopt the leftover WrongGPU files as an install of " + name + L"?\n\n" + what + L" Then Update, Repair and Uninstall work as for any install."; -} -std::vector LeftoversButtons(bool clean) { + // 0.6.1: beside an OptiScaler WrongGPU didn't install they are another mod's setup's: said first, Cancel the default + const wstring other = otherSetup ? L" Another mod's setup uses them: an OptiScaler that WrongGPU didn't install is next to them. Removing or adopting them " + L"can break that mod, so leave them alone unless you removed it." + : L""; + return clean ? L"Remove the leftover WrongGPU files from " + name + L"?\n\n" + what + other + L" Only these files are removed." + : L"Adopt the leftover WrongGPU files as an install of " + name + L"?\n\n" + what + other + L" Then Update, Repair and Uninstall work as for any install."; +} +std::vector LeftoversButtons(bool clean, bool otherSetup) { + if (otherSetup) return {{L"Show details", 2}, {clean ? L"Clean up anyway" : L"Adopt anyway", 1, false, clean}, {L"Leave them alone", 0, true}}; return {{L"Show details", 2}, {L"Cancel", 0}, {clean ? L"Clean up" : L"Adopt", 1, true, clean}}; } // "Installed for this user" with the games that kept their own uninstall entry (an adoption that failed), if any diff --git a/clean/installer/src/wg_core/coexist.cpp b/clean/installer/src/wg_core/coexist.cpp index 1500f9f1..b29ad3a4 100644 --- a/clean/installer/src/wg_core/coexist.cpp +++ b/clean/installer/src/wg_core/coexist.cpp @@ -10,6 +10,8 @@ #include "checks.h" // FindAntiCheat, VersionLess #include "gamerules.h" #include "optiscaler.h" +#include "pe.h" +#include "rr.h" namespace wg { @@ -84,7 +86,8 @@ bool CoexistReport::has(Tool t) const { for (auto& f : findings) if (f.tool == t bool CoexistReport::needsSwitch() const { for (auto& f : findings) if (f.decision == Decision::AskSwitch) return true; return false; } std::vector CoexistReport::Warnings() const { std::vector w; - for (auto& f : findings) if (f.decision == Decision::Chain || f.decision == Decision::Warn) w.push_back(f.what + L": " + f.message); + for (auto& f : findings) // (other plugins: the install says what it did about them in its own words) + if ((f.decision == Decision::Chain || f.decision == Decision::Warn) && f.tool != Tool::OtherPlugin) w.push_back(f.what + L": " + f.message); if (proxy.untested && !proxy.name.empty()) w.push_back(L"OptiScaler as " + proxy.name + L" next to ReShade / Special K: an untested combination"); return w; } @@ -185,20 +188,32 @@ ProxyChoice PickProxy(const wstring& exeDir, const Record* ours, const wstring& return c; } -// ---- WrongGPU's own OptiScaler setup --------------------------------------------------------------------------------- -std::set OurOptiHashes(Context& ctx, const Record* ours) { - std::set h; - if (ours) // what our install wrote (the record's copies: WrongGPU's payload and the OptiScaler files of its setup) - for (auto& e : ours->e) - if (e.action == L"copy" && !e.inst.empty() && e.owner != L"adopted" && e.owner != L"moved") h.insert(Lower(e.inst)); - if (ctx.opti.ok()) { // the OptiScaler package this launcher installs from - const wstring dll = Join(ctx.opti.dir, L"OptiScaler.dll"); - if (IsFile(dll)) h.insert(Lower(Sha256File(dll))); - } - return h; +// ---- other setups' OptiScaler plugins (0.6.1) ------------------------------------------------------------------------ +bool ExportsRrContract(const wstring& path) { + MappedFile f(path, 256ull << 20); // the file's bytes only: never loaded as a module + return f.data && ReadPeExports(f.data, f.size).count(kRrContractExport) > 0; +} +// The .asi files of OptiScaler's plugin folders that the install record does not name with that hash; withMarker: those that +// export WrongGPU RR's marker (true) or the others (false) +static std::vector UnrecordedPlugins(const wstring& exeDir, const Record* ours, bool withMarker) { + std::vector out; + for (auto sub : kPluginDirs) + for (auto& f : ListFiles(Join(exeDir, sub), L"*.asi")) { + const wstring rel = f.substr(exeDir.size() + 1); + bool mine = false; + if (ours) + for (auto& e : ours->e) + if (e.action == L"copy" && IEq(e.rel, rel) && !e.inst.empty()) { mine = IEq(Sha256File(f), e.inst); break; } + if (!mine && ExportsRrContract(f) == withMarker) out.push_back(rel); + } + return out; } -bool IsOurOptiScaler(const std::set& ourHashes, const wstring& path) { - return !ourHashes.empty() && IsFile(path) && ourHashes.count(Lower(Sha256File(path))) > 0; +std::vector ForeignPlugins(const wstring& exeDir, const Record* ours) { return UnrecordedPlugins(exeDir, ours, false); } +std::vector OurPluginsFromOtherPackages(const wstring& exeDir, const Record* ours) { return UnrecordedPlugins(exeDir, ours, true); } +wstring ForeignPluginsText(const std::vector& plugins) { + return L"Other OptiScaler plugins are in this game (" + JoinList(plugins) + L"). They may hook Ray Reconstruction as WrongGPU's RR plugin does, so " + L"WrongGPU's Ray Reconstruction was left out. To use it, install again and choose to move them aside (they are backed up and put back " + L"when WrongGPU is uninstalled)."; } // ---- the assessment -------------------------------------------------------------------------------------------------- @@ -208,13 +223,14 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& std::map ourHash; // lower-case path relative to dir -> installed hash if (ours) for (auto& e : ours->e) if (e.action == L"copy") ourHash[Lower(e.rel)] = e.inst; const bool sameDir = IEq(FullPath(exeDir), FullPath(dir)); - // WrongGPU's OptiScaler setup (the record has OptiScaler.ini): its log and settings are ours, and so is an OptiScaler - // DLL whose hash the record or the package this launcher installs from has (whatever name it loads as) + // WrongGPU's OptiScaler setup (the record has OptiScaler.ini): its log and settings are ours, and so is the OptiScaler + // DLL the record copied under that name with that hash (isOurs; 0.6.1: never by a hash alone under another name, never + // by the package's hash: another setup may use the same OptiScaler build) const bool hostedOurs = ours && HostedRecord(*ours) && sameDir; - const std::set ourOpti = OurOptiHashes(ctx, hostedOurs ? ours : nullptr); auto isOurs = [&](const wstring& rel) { if (!sameDir) return false; - if (hostedOurs && (IEq(rel, L"OptiScaler.log") || IEq(rel, L"OptiScaler.ini"))) return true; + if (hostedOurs && IEq(rel, L"OptiScaler.log")) return true; + if (hostedOurs && IEq(rel, L"OptiScaler.ini")) return OptiIniIsOurs(dir, *ours); // 0.6.1: while its keys point at WrongGPU's files auto it = ourHash.find(Lower(rel)); if (it == ourHash.end()) return false; if (EndsWithI(rel, L".ini") || EndsWithI(rel, L".log")) return true; // settings and logs of our install @@ -250,9 +266,7 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& const wstring p = Join(exeDir, n); if (!IsFile(p) || isOurs(n)) continue; if (IEq(n, kReFrameworkDll) && IsReFrameworkDll(p)) { refw = true; continue; } - const Fingerprint fp = IdentifyFile(p); - if (fp.tool == Tool::OptiScaler && hostedOurs && IsOurOptiScaler(ourOpti, p)) continue; // our setup's OptiScaler under another name - seen.push_back({n, fp}); + seen.push_back({n, IdentifyFile(p)}); } auto filesOf = [&](Tool t) { std::vector v; for (auto& s : seen) if (s.fp.tool == t) v.push_back(s.rel); return v; }; auto fpOf = [&](Tool t) -> const Fingerprint* { for (auto& s : seen) if (s.fp.tool == t) return &s.fp; return nullptr; }; @@ -268,10 +282,14 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& : wstring(L"Stays where it is; WrongGPU works next to it.")); } - // our OptiScaler setup - if (ours && HostedRecord(*ours)) - add(Tool::OptiScaler, Decision::Managed, L"WrongGPU's OptiScaler setup" + (ours->proxy.empty() ? wstring() : L" as " + ours->proxy), - ours->proxy.empty() ? std::vector{} : std::vector{ours->proxy}, L"install record", L"Installed by WrongGPU: updated and removed with it."); + // our OptiScaler setup. 0.6.1: one finding per file: a proxy name another setup's file holds now is that file's finding + // (listed below), not this one's + if (ours && HostedRecord(*ours)) { + const bool proxyOurs = !ours->proxy.empty() && (!IsFile(Join(exeDir, ours->proxy)) || isOurs(ours->proxy)); + add(Tool::OptiScaler, Decision::Managed, + L"WrongGPU's OptiScaler setup" + (proxyOurs ? L" as " + ours->proxy : ours->proxy.empty() ? wstring() : L" (its " + ours->proxy + L" was replaced)"), + proxyOurs ? std::vector{ours->proxy} : std::vector{}, L"install record", L"Installed by WrongGPU: updated and removed with it."); + } // the player's OptiScaler: ask to switch (owner decision); two copies: refused until the player keeps one { @@ -339,6 +357,25 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& L"\\ instead (OptiScaler's [Plugins] Path), so it is not started twice."); } + // 0.6.1: other setups' plugins in OptiScaler's plugin folders: in a Ray Reconstruction game WrongGPU's RR stays out unless + // the player moves them aside (they may hook RR too); elsewhere they stay beside WrongGPU's plugin + // (gap 5a: the plugin folders are the exe folder's; when the install folder is another one, the record that names their + // files is the exe folder's own, if there is one: an earlier install there is not "another setup") + Record exeDirRecord; + const Record* pluginRecord = sameDir ? ours : LoadRecord(RecordPath(exeDir), exeDirRecord) && !exeDirRecord.legacy ? &exeDirRecord : nullptr; + if (const auto kit = OurPluginsFromOtherPackages(exeDir, pluginRecord); !kit.empty()) + add(Tool::WrongGPU, Decision::Inform, L"WrongGPU RR (from another package)", kit, L"export " + FromUtf8(kRrContractExport) + L" in " + kit[0], + L"WrongGPU's own Ray Reconstruction plugin, placed by another package. It stays where it is and is never moved aside."); + r.foreignPlugins = ForeignPlugins(exeDir, pluginRecord); + if (!r.foreignPlugins.empty()) { + r.foreignPluginsBlockRr = DetectRr(exe).uses; + add(Tool::OtherPlugin, r.foreignPluginsBlockRr ? Decision::Warn : Decision::Inform, L"Other OptiScaler plugins (" + JoinList(r.foreignPlugins) + L")", + r.foreignPlugins, L"file " + r.foreignPlugins[0], + r.foreignPluginsBlockRr ? L"They may hook Ray Reconstruction as WrongGPU's RR plugin does: WrongGPU's Ray Reconstruction stays out of this game unless " + L"you choose to move them aside when you install (backed up, put back when WrongGPU is uninstalled)." + : L"They stay; WrongGPU's plugin goes beside them."); + } + // CET, RED4ext, UE4SS: they keep their names (the picker never takes them) auto notMicrosoft = [&](const wchar_t* n) { for (auto& s : seen) if (IEq(s.rel, n)) return s.fp.tool != Tool::Microsoft; return false; }; { diff --git a/clean/installer/src/wg_core/coexist.h b/clean/installer/src/wg_core/coexist.h index 057da687..5f11a989 100644 --- a/clean/installer/src/wg_core/coexist.h +++ b/clean/installer/src/wg_core/coexist.h @@ -61,6 +61,8 @@ struct CoexistReport { bool asiLoader = false; // Ultimate ASI Loader: WrongGPU's plugin goes to its own folder (kAsiPluginOwnDir) bool hipTool = false; // another HIP-based tool: version.dll is never taken wstring playersOptiProxy; // the name the player's OptiScaler loads as (reused by a switch) + std::vector foreignPlugins; // 0.6.1: other setups' .asi files in OptiScaler's plugin folders (ForeignPlugins) + bool foreignPluginsBlockRr = false; // ...and the game uses Ray Reconstruction: WrongGPU's RR stays out unless they are moved aside GraphicsApi api; const Finding* refusal() const; // the first Refuse finding, or null bool has(Tool t) const; @@ -73,16 +75,29 @@ inline const wchar_t* const kProxyOrder[] = {L"dxgi.dll", L"winmm.dll", L"versio inline const wchar_t* const kNeverProxy[] = {L"d3d12.dll", L"dinput8.dll", L"dwmapi.dll", L"xinput1_3.dll", L"xinput1_4.dll", L"xinput9_1_0.dll"}; // The plugin's folder when Ultimate ASI Loader is present (it would load plugins\WrongGPU.asi a second time). const wchar_t* const kAsiPluginOwnDir = L"wronggpu-plugins"; +// 0.6.1: the folders OptiScaler loads plugins from (next to it, in its own OptiScaler\ folder, or WrongGPU's own folder). +inline const wchar_t* const kPluginDirs[] = {L"plugins", L"OptiScaler\\plugins", L"wronggpu-plugins"}; +// The .asi files in those folders next to the exe that are not WrongGPU's install's own (the record copied them there with +// that hash), relative to exeDir. Another setup's plugin may hook Ray Reconstruction as WrongGPU's RR plugin does: by default +// WrongGPU's RR stays out of such a game (with a warning); with the player's OK (Consent::movePlugins) they are moved aside +// (backed up, put back on uninstall) and WrongGPU's RR goes in. Never by a plugin's name alone. +std::vector ForeignPlugins(const wstring& exeDir, const Record* ours); +// 0.6.1 (gap 4): WrongGPU's RR plugin exports this marker (clean/rr_f/proxy/include/wg_rr_settings_contract.h, +// WG_RR_CONTRACT_EXPORT). A plugin file that exports it is WrongGPU's own RR plugin whatever its name or hash (a copy another +// package placed from the integration kit): never "another setup's plugin", never moved aside. Read from the file's PE +// export table, never by loading it. +const char* const kRrContractExport = "WrongGPU_GetSettingsContract"; +bool ExportsRrContract(const wstring& path); +// Those copies in OptiScaler's plugin folders that the install record doesn't name with that hash (relative to exeDir): the +// rules table shows them as "WrongGPU RR (from another package)". +std::vector OurPluginsFromOtherPackages(const wstring& exeDir, const Record* ours); +// The warning when they keep WrongGPU's RR out, and the line of a plugin moved aside with the OK. +wstring ForeignPluginsText(const std::vector& plugins); // Every finding for one game (exe) and its install folder (dir): fingerprints of the DLLs next to the exe, the tools' // folders and marker files, running overlays, anti-cheat, the graphics API, older installs. ours: the game's install // record (its files are not "other tools"); null when there is none. CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& dir, const Record* ours); -// WrongGPU's own OptiScaler (bug 2026-10-17: a hosted install's OptiScaler.log made it "your OptiScaler"): the hashes of -// what the record wrote (owners wg / wg-optibundle) and of the package's OptiScaler.dll this run installs from. An -// OptiScaler DLL with one of these hashes is never the player's, under whichever name it loads. -std::set OurOptiHashes(Context& ctx, const Record* ours); -bool IsOurOptiScaler(const std::set& ourHashes, const wstring& path); // The proxy picker (design section 5): our earlier install's name, else the first name of kProxyOrder that is free, // never a name a recognised tool, an unknown file or a game's own Windows DLL holds (version.dll never when hipTool); // the name the player's OptiScaler had (a switch moves it aside) only when no other is free. The reason says what diff --git a/clean/installer/src/wg_core/detect.cpp b/clean/installer/src/wg_core/detect.cpp index 1c4dbfdc..6828fbd1 100644 --- a/clean/installer/src/wg_core/detect.cpp +++ b/clean/installer/src/wg_core/detect.cpp @@ -486,12 +486,21 @@ GameTarget InspectGame(Context& ctx, const wstring& exe, const wstring& displayN t.antiCheat = FindAntiCheat(exe); t.conflicts = FindConflicts(t.dir, t.exeDir); if (t.installed) { // the OptiScaler files of our own earlier install are not "another mod", nor is the log it wrote - std::set ours; - for (auto& e : t.record.e) if (e.action == L"copy") ours.insert(Lower(e.rel)); - if (HostedRecord(t.record)) ours.insert(L"optiscaler.log"); - const std::set optiHashes = HostedRecord(t.record) ? OurOptiHashes(ctx, &t.record) : std::set{}; + // 0.6.1: a DLL under a name the record copied counts as ours only with the record's hash; another setup's OptiScaler + // that replaced WrongGPU's proxy is another mod (Repair and Update ask the switch question for it). Settings and + // logs go by name (OptiScaler's menu saves its ini), as the restore treats them. + std::map ours; // lower-case name -> installed hash + for (auto& e : t.record.e) if (e.action == L"copy") ours[Lower(e.rel)] = e.inst; + if (HostedRecord(t.record)) ours[L"optiscaler.log"] = L""; + auto isOurs = [&](const wstring& f) { + const auto it = ours.find(Lower(f)); + if (it == ours.end()) return false; + if (IEq(f, L"OptiScaler.ini")) return OptiIniIsOurs(t.dir, t.record); // (fix 4: its keys still point at WrongGPU's files) + if (EndsWithI(f, L".ini") || EndsWithI(f, L".log")) return true; + return !it->second.empty() && IEq(Sha256File(Join(t.dir, f)), it->second); + }; auto& mf = t.conflicts.modFiles; - mf.erase(std::remove_if(mf.begin(), mf.end(), [&](const wstring& f) { return ours.count(Lower(f)) > 0 || IsOurOptiScaler(optiHashes, Join(t.dir, f)); }), mf.end()); + mf.erase(std::remove_if(mf.begin(), mf.end(), isOurs), mf.end()); if (mf.empty() && t.conflicts.outside.empty()) t.conflicts.mods.clear(); } t.coexist = AssessCoexistence(ctx, exe, t.dir, t.installed ? &t.record : nullptr); diff --git a/clean/installer/src/wg_core/fingerprint.cpp b/clean/installer/src/wg_core/fingerprint.cpp index 1f61ab36..c7fd77b3 100644 --- a/clean/installer/src/wg_core/fingerprint.cpp +++ b/clean/installer/src/wg_core/fingerprint.cpp @@ -32,6 +32,7 @@ const ToolInfo kTools[] = { // what players read (owner 2026-11-04): its name and key are generic {Tool::NrOnAmd, L"Another upscaler mod", "other-upscaler-mod"}, {Tool::ReFramework, L"REFramework", "reframework"}, + {Tool::OtherPlugin, L"another OptiScaler plugin", "optiscaler-plugin"}, {Tool::AntiCheat, L"anti-cheat", "anti-cheat"}, {Tool::Overlay, L"an overlay", "overlay"}, {Tool::GameApi, L"the game's graphics API", "graphics-api"}, @@ -96,10 +97,16 @@ bool SignerMentions(const PeImage& img, const char* needle) { const char* const kVendorSigner = "nvidia corporation"; // the signer of the DLSS DLL (what older OptiScaler layouts copy as nvngx.dll) // Product words of the version resource (CompanyName, ProductName, FileDescription, InternalName, OriginalFilename). +// OptiScaler first (0.6.1): an OptiScaler build whose version resource also names WrongGPU (an edition of it) is an +// OptiScaler, never WrongGPU's file; whether it is the OptiScaler of WrongGPU's own setup is decided by the install record's +// name and hash only (coexist.cpp AssessCoexistence, detect.cpp InspectGame). WrongGPU's menu plugin says "WrongGPU OptiScaler plugin": a plugin for +// OptiScaler, not OptiScaler (kOptiPluginWords). struct ResourceWord { const wchar_t* word; Tool tool; }; +const wchar_t* const kOptiPluginWords = L"optiscaler plugin"; const ResourceWord kResourceWords[] = { + {L"optiscaler", Tool::OptiScaler}, {L"wronggpu", Tool::WrongGPU}, {L"dlss 4.5 amd", Tool::WrongGPULegacy}, {L"dlss45", Tool::WrongGPULegacy}, - {L"optiscaler", Tool::OptiScaler}, {L"reshade", Tool::ReShade}, {L"special k", Tool::SpecialK}, {L"specialk", Tool::SpecialK}, + {L"reshade", Tool::ReShade}, {L"special k", Tool::SpecialK}, {L"specialk", Tool::SpecialK}, {L"ultimate asi loader", Tool::AsiLoader}, {L"cyber engine tweaks", Tool::Cet}, {L"red4ext", Tool::Red4ext}, {L"ue4ss", Tool::Ue4ss}, {L"fakenvapi", Tool::FakeNvapi}, }; @@ -168,8 +175,9 @@ Fingerprint IdentifyBytes(const uint8_t* b, size_t n, const wstring& name) { f.company = v.Get(L"CompanyName"); f.product = v.Get(L"ProductName"); const wstring words = LowerW(f.company + L"|" + f.product + L"|" + v.Get(L"FileDescription") + L"|" + v.Get(L"InternalName") + L"|" + v.Get(L"OriginalFilename")); + const bool optiPlugin = words.find(kOptiPluginWords) != wstring::npos; // a plugin for OptiScaler (WrongGPU.asi), not OptiScaler for (auto& w : kResourceWords) - if (words.find(w.word) != wstring::npos) { f.tool = w.tool; f.evidence = wstring(L"version resource: ") + (f.product.empty() ? f.company : f.product); return f; } + if (words.find(w.word) != wstring::npos && !(optiPlugin && w.tool == Tool::OptiScaler)) { f.tool = w.tool; f.evidence = wstring(L"version resource: ") + (f.product.empty() ? f.company : f.product); return f; } if ((api == Tool::Dxvk && words.find(L"dxvk") != wstring::npos) || (api == Tool::Vkd3d && words.find(L"vkd3d") != wstring::npos)) { f.tool = api; f.evidence = L"version resource: " + (f.product.empty() ? f.company : f.product) + as; return f; } diff --git a/clean/installer/src/wg_core/fingerprint.h b/clean/installer/src/wg_core/fingerprint.h index 56121aff..10a864b8 100644 --- a/clean/installer/src/wg_core/fingerprint.h +++ b/clean/installer/src/wg_core/fingerprint.h @@ -11,7 +11,8 @@ namespace wg { enum class Tool { Unknown, // a file none of the rules recognise (never overwritten, never taken as a proxy name) Microsoft, // a Windows component the game ships (its version resource says Microsoft) - WrongGPU, // ours (version resource "WrongGPU", or a hash of one of our releases) + WrongGPU, // version resource or text "WrongGPU" (a hint only: what WrongGPU removes goes by the install record and + // our releases' hashes); an OptiScaler build that also names WrongGPU is OptiScaler WrongGPULegacy, // WrongGPU 0.1.x / 0.2.x, published as "DLSS 4.5 AMD" OptiScaler, ReShade, @@ -28,6 +29,7 @@ enum class Tool { VendorDll, // a DLL whose version resource or signer names NVIDIA (e.g. the game's DLSS DLL copied as nvngx.dll) NrOnAmd, // the "DLSS-NR on AMD" mod ReFramework, // REFramework (a mod framework of RE Engine games): recognised by gamerules.h, it stays + OtherPlugin, // (rules table only, 0.6.1: another setup's .asi in OptiScaler's plugin folders, coexist.h ForeignPlugins) AntiCheat, // (rules table only: anti-cheat markers, not a fingerprint) Overlay, // (rules table only: a running overlay or injector) GameApi, // (rules table only: the game's graphics API) diff --git a/clean/installer/src/wg_core/install.cpp b/clean/installer/src/wg_core/install.cpp index 8fdc0a70..61b6c583 100644 --- a/clean/installer/src/wg_core/install.cpp +++ b/clean/installer/src/wg_core/install.cpp @@ -180,7 +180,16 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod } // Ray Reconstruction (rr.h): a game that uses it gets this build's RR files too (OptiScaler setup only: the RR plugin is // one of OptiScaler's plugins) - const bool rr = (!kDirectRoute || ctx.opti.ok()) && RrPayloadAvailable(ctx) && DetectRr(target.exe).uses; + const bool rrGame = (!kDirectRoute || ctx.opti.ok()) && RrPayloadAvailable(ctx) && DetectRr(target.exe).uses; + // 0.6.1: another setup's plugins in OptiScaler's plugin folders may hook RR too: WrongGPU's RR stays out unless the player + // chose to move them aside (then backed up as moved, below); the earlier install's own plugins are not "another setup's" + const std::vector foreignAsi = rrGame ? ForeignPlugins(target.exeDir, target.installed ? &target.record : nullptr) : std::vector{}; + const bool rr = rrGame && (foreignAsi.empty() || consent.movePlugins); + if (rrGame && !rr) { + const wstring w = ForeignPluginsText(foreignAsi); + LogLine(ctx, L"Ray Reconstruction: " + w); + warnings.push_back(w); + } if (rr) for (size_t i = 0; i < ctx.data->rrCount; ++i) { const PayloadFile& f = ctx.data->rrFiles[i]; @@ -268,13 +277,14 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod ui.log(L"The earlier installation was removed and the game's original files are back; the new version was not installed (your settings were kept)."); } } earlierGone{dir, ui}; + std::map keptByRestore; // recorded files the restore left in place (changed since the install), with its warning if (IsFile(RecordPath(dir))) { ui.log(L"An earlier installation was found - restoring the original files first."); Record old; if (LoadRecord(RecordPath(dir), old)) MigrateSettings(ctx, dir, old.version, ui); earlierGone.armed = true; try { - for (auto& w : DoRestore(ctx, dir, ui, false, true)) warnings.push_back(w); + for (auto& w : DoRestore(ctx, dir, ui, false, true, &keptByRestore)) warnings.push_back(w); } catch (const SetupError&) { // nothing is lost: the restore can be run again from the record and the backup ui.log(L"The earlier installation could not be removed; its record and backup were left as they are. Close anything that uses the game's files, then run setup again or uninstall it."); throw; @@ -500,6 +510,26 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod const Conflicts now = FindConflicts(dir, target.exeDir); if (!now.outside.empty() || !now.legacyRecordDir.empty()) Fail(L"Files of another mod or an older install could not be handled automatically: " + (now.outside.empty() ? now.legacyRecordDir : now.outside[0]), EXIT_OTHER_MODS); + // 0.6.1: the player's OK is checked against what is in the folder now, after the restore: another setup's OptiScaler that + // replaced WrongGPU's proxy stays through the restore and is never moved aside without the switch question's answer. The + // files the earlier install moved aside or replaced with the player's OK (its record's disable entries, and copies over a + // file that was there, backed up) come back through the restore: byte for byte those, they go aside again on that OK; + // anything else needs it anew + if (now.modsFound() && !consent.moveMods) { + std::map movedBefore; // lower-case name -> the hash the player's OK was for + if (target.installed) + for (auto& e : target.record.e) + if ((e.action == L"disable" || (e.action == L"copy" && e.existed)) && !e.orig.empty()) movedBefore[Lower(e.rel)] = e.orig; + wstring list; + for (auto& f : now.modFiles) { + const auto it = movedBefore.find(Lower(f)); + if (it != movedBefore.end() && IEq(Sha256File(Join(dir, f)), it->second)) continue; + list += (list.empty() ? L"" : L", ") + f; + } + if (!list.empty()) + Fail(L"This game has its own OptiScaler or another upscaler mod (" + list + L"). Switch to WrongGPU's OptiScaler setup? " + L"Your files are backed up and put back byte for byte when WrongGPU is uninstalled.", EXIT_OTHER_MODS); + } Record m; m.version = ctx.data->version; m.game = dir; m.exe = target.exe; m.status = target.validated ? L"validated" : L"experimental"; m.regkey = ctx.perGameEntry ? RegKeyFor(dir) : L""; m.model = ModelFile(ctx); m.modelM = modelM.outcome; LogLine(ctx, L"target " + target.exe + L" | install folder " + dir + L" | status " + m.status); @@ -561,12 +591,37 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod if (!IsAmdFidelityFxName(f) && std::find_if(optiFiles.begin(), optiFiles.end(), [&](const OptiFile& o) { return IEq(o.rel, f); }) == optiFiles.end()) disable.push_back(f); for (auto& f : now.legacyFiles) disable.push_back(f); + // other setups' plugins, moved aside with the player's OK so WrongGPU's RR plugin is the only one (fix 2); one at a path + // this install writes is backed up by its copy entry instead + if (rr && consent.movePlugins) + for (auto& f : ForeignPlugins(target.exeDir, nullptr)) { + const wstring rel = IEq(FullPath(target.exeDir), FullPath(dir)) ? f : wstring(); + if (rel.empty() || std::find_if(optiFiles.begin(), optiFiles.end(), [&](const OptiFile& o) { return IEq(o.rel, rel); }) != optiFiles.end()) continue; + bool written = false; + for (auto& pf : *ctx.data) written = written || (payloadUsed(pf) && IEq(payloadRel(pf), rel)); + if (written || std::find_if(disable.begin(), disable.end(), [&](const wstring& d) { return IEq(d, rel); }) != disable.end()) continue; + disable.push_back(rel); + warnings.push_back(L"Moved aside with your OK: " + rel + L" (another OptiScaler plugin; kept in the backup and put back when WrongGPU is uninstalled)."); + } for (auto& name : disable) { wstring tp = Target(dir, name); if (!IsFile(tp)) continue; Entry e; e.action = L"disable"; e.rel = name; e.existed = true; e.orig = Sha256File(tp); if (e.orig.empty()) Fail(L"Cannot read the existing file " + tp); m.e.push_back(e); + // a file the restore left in place (another setup's, over WrongGPU's) that the switch now moves aside: said as that + const auto k = keptByRestore.find(Lower(name)); + if (k != keptByRestore.end()) + for (auto& w : warnings) + if (w == k->second) w = L"Moved aside with your OK: " + name + L" (another setup's file that had replaced WrongGPU's; kept in the backup and put back when WrongGPU is uninstalled)."; + } + // another setup's file the restore left in place (fix 4: its OptiScaler.ini) that this install now replaces with the + // switch question's OK: backed up (an entry that existed) and said as that + for (auto& e : m.e) { + const auto k = e.action == L"copy" && e.existed ? keptByRestore.find(Lower(e.rel)) : keptByRestore.end(); + if (k != keptByRestore.end()) + for (auto& w : warnings) + if (w == k->second) w = L"Replaced with your OK: " + e.rel + L" (another setup's; kept in the backup and put back when WrongGPU is uninstalled)."; } InferOwners(ctx, m); // record v2: who owns each file, what this install wrote, the proxy and why SetPayloadLine(ctx, m); diff --git a/clean/installer/src/wg_core/install.h b/clean/installer/src/wg_core/install.h index 36521097..e2baee30 100644 --- a/clean/installer/src/wg_core/install.h +++ b/clean/installer/src/wg_core/install.h @@ -9,7 +9,7 @@ namespace wg { struct CompareDll { wstring path, version, game; std::vector v; }; -struct Consent { bool moveMods = false, removeOld = false; }; +struct Consent { bool moveMods = false, removeOld = false, movePlugins = false; }; // movePlugins (0.6.1): other setups' plugins aside (ForeignPlugins) void RemoveEarlierDirect(Context& ctx, const GameTarget& target, Ui& ui, std::vector& warnings); wstring CompareRecordFile(); diff --git a/clean/installer/src/wg_core/known_releases.h b/clean/installer/src/wg_core/known_releases.h index a75aa473..5e4acca3 100644 --- a/clean/installer/src/wg_core/known_releases.h +++ b/clean/installer/src/wg_core/known_releases.h @@ -70,6 +70,12 @@ inline const KnownFile kKnownFiles[] = { {L"0.5.5-ea", L"amd_fidelityfx_dx12.dll", 2182144ull, L"3511adb5994cb217a85bd06a662989338f7e219b3f18c49b9d12de3ac0c7300f"}, {L"0.5.5-ea", L"wronggpu_runtime.dll", 24689152ull, L"331bc00e02f048a990a4c37362f8001b2c1eb31c27bd57b9ed58f6a66222a1be"}, {L"0.5.5-ea", L"plugins\\WrongGPU.asi", 910336ull, L"e9aab52cc1b4a5e411a65560eacdfe26a442c6b8085d318a125e114e2e0bac25"}, + {L"0.6.0", L"amd_fidelityfx_dx12.dll", 2402816ull, L"5de1610d611d882f9d6aadd86ebba58b5ce496d298a1975c916099105346164f"}, + {L"0.6.0", L"wronggpu-license.txt", 3826ull, L"1578d31524b3d6b3da4371637275e3f46ba183a47874e7f43d6cbe9c373a6230"}, + {L"0.6.0", L"wronggpu-notices.txt", 4417ull, L"ebdd1bf59e6b3a401892c16b707fe3f98213835ba3b97ee4be23a28a878dce6f"}, + {L"0.6.0", L"wronggpu_runtime.dll", 73618432ull, L"8087a1e613224ac18d082553d5fa75ecef36a15d5752b80ee0f0aabed8eef4ba"}, + {L"0.6.0", L"plugins\\WrongGPU.asi", 916480ull, L"ca0a2d9434a0bdadbe334e13af1c20689cadd45ec59001c0f92d48da50874e89"}, + {L"0.6.0", L"plugins\\WrongGPU-RR.asi", 366080ull, L"349062ecad3756b1d1b0e33ec922f959d17f93c78c1372e82c5f0763a9e7b19a"}, }; } // namespace wg diff --git a/clean/installer/src/wg_core/launcher.cpp b/clean/installer/src/wg_core/launcher.cpp index 8d17516a..b6032cac 100644 --- a/clean/installer/src/wg_core/launcher.cpp +++ b/clean/installer/src/wg_core/launcher.cpp @@ -401,7 +401,7 @@ GameEntry EntryFor(Context& ctx, const wstring& exeIn, const wstring& name, cons else if (const Finding* no = t.coexist.refusal()) { g.status = GameStatus::Refused; g.statusText = L"Refused: " + no->what; } else if (!g.needs.empty() && !g.needsFound) { g.status = GameStatus::NeedsPrereq; g.statusText = L"Needs " + g.needs + L": " + g.needsGame + L" blocks OptiScaler without it"; } else if (t.conflicts.oldFound()) { g.status = GameStatus::OldInstall; g.statusText = L"Has an older WrongGPU (DLSS 4.5 AMD): Install removes it first"; } - else if (!(g.leftovers = FindLeftovers(ctx, g.dir)).empty()) { + else if (!(g.leftovers = FindLeftovers(ctx, g.dir)).empty() && !(g.leftoversOtherSetup = LeftoversUsedByOtherSetup(g.dir, g.leftovers))) { g.status = GameStatus::Leftovers; g.statusText = L"Leftover WrongGPU files without a record: " + LeftoverSummary(g.leftovers) + L" - Clean up or Adopt"; } @@ -977,7 +977,14 @@ static void InstallOp(Context& ctx, const OpRequest& r, Ui& ui, OpResult& res) { if (int code = c.firstFailure(r.force, why)) Fail(why, code); if (!target.validated && !r.experimental && !target.installed) Fail(target.name + L" is experimental (not tested end to end). Confirm to install anyway.", EXIT_EXPERIMENTAL); // leftover WrongGPU files without a record: cleaned up first only with the player's OK (never automatic) - const std::vector leftovers = target.installed ? std::vector{} : FindLeftovers(ctx, dir); + std::vector leftovers = target.installed ? std::vector{} : FindLeftovers(ctx, dir); + // 0.6.1: beside another mod's OptiScaler they are that setup's: never removed first; the install backs up any it replaces + if (LeftoversUsedByOtherSetup(dir, leftovers)) { + res.notes.push_back(L"WrongGPU files " + wstring(kLeftoversOtherSetup) + L" were left alone: " + LeftoverSummary(leftovers) + + L" (any the install replaces is backed up and put back when WrongGPU is uninstalled)"); + LogLine(ctx, res.notes.back()); + leftovers.clear(); + } if (!leftovers.empty() && !r.removeOld) Fail(L"Leftover WrongGPU files without an install record are in this game: " + LeftoverSummary(leftovers) + L". Confirm to clean them up first (only files that match WrongGPU's releases are removed), or adopt them as an install.", EXIT_OLD_INSTALL); @@ -1021,7 +1028,7 @@ static void InstallOp(Context& ctx, const OpRequest& r, Ui& ui, OpResult& res) { oldJournal.erase(std::remove_if(oldJournal.begin(), oldJournal.end(), [&](const IniKeyChange& c) { return OptInKey(target.exe, c); }), oldJournal.end()); // rc6 L5: values OptiScaler's own menu saved over the launcher's (the journal's keys, JournalOutside) carry over to the new // OptiScaler.ini as the player's choices, as the OptiScaler tab's Keep would make them (locked keys stay WrongGPU's) - if (target.installed && HostedRecord(target.record)) { + if (target.installed && HostedRecord(target.record) && OptiIniIsOurs(dir, target.record)) { // (0.6.1: never another setup's values) string current; if (ReadAll(Join(dir, L"OptiScaler.ini"), current)) for (auto& o : JournalOutside(current, oldJournal, L"OptiScaler.ini")) { @@ -1035,7 +1042,7 @@ static void InstallOp(Context& ctx, const OpRequest& r, Ui& ui, OpResult& res) { const RrConfigFix keepFix = target.installed ? target.record.rrconfig : !wrongDir.empty() ? wrong.rrconfig : RrConfigFix(); string keepBackup = wrongDir.empty() ? string() : wrongFixBackup; if (keepFix.backup && wrongDir.empty()) ReadAll(RrConfigBackupPath(dir), keepBackup); - Consent consent; consent.moveMods = r.moveMods; consent.removeOld = r.removeOld; + Consent consent; consent.moveMods = r.moveMods; consent.removeOld = r.removeOld; consent.movePlugins = r.movePlugins; try { for (auto& w : DoInstall(ctx, target, model, consent, ui, sys.hip)) res.warnings.push_back(w); } catch (const SetupError&) { @@ -1116,6 +1123,9 @@ OpResult RunOp(Context& ctx, const OpRequest& r, Ui& ui) { const std::vector lo = FindLeftovers(ctx, r.dir); if (lo.empty()) Fail(L"There are no leftover WrongGPU files (without an install record) in " + r.dir + L".", EXIT_NOT_INSTALLED); if (!r.exe.empty() && GameRunning(r.exe)) Fail(BaseName(r.exe) + L" is running. Close it first.", EXIT_REFUSED); + if (!r.force && LeftoversUsedByOtherSetup(r.dir, lo)) // 0.6.1: left alone unless the player confirms (force) + Fail(L"These WrongGPU files are " + wstring(kLeftoversOtherSetup) + L", so they are left alone: removing or adopting them can break that mod. " + L"Confirm to " + (r.op == Op::CleanLeftovers ? L"remove" : L"adopt") + L" them anyway.", EXIT_REFUSED); if (r.op == Op::CleanLeftovers) { res.notes = CleanLeftovers(ctx, r.dir, lo); res.message = L"Leftover WrongGPU files removed from " + r.dir + L" (" + LeftoverSummary(lo) + L")"; @@ -1154,6 +1164,7 @@ string JobText(const OpRequest& r, const wstring& localAppData, const wstring& l if (r.hasProfile) for (size_t i = 0; i < kSettingCount; ++i) t += string("profile.") + kSettings[i].key + "=" + r.profile.get(kSettings[i].key) + "\r\n"; for (auto& e : r.optiEdits) t += "optikey." + e.first + "=" + e.second + "\r\n"; + if (r.movePlugins) t += "moveplugins=1\r\n"; if (r.optiReset) t += "optireset=1\r\n"; if (r.optiKeep) t += "optikeep=1\r\n"; if (r.optiOnly) t += "optionly=1\r\n"; @@ -1184,6 +1195,7 @@ bool ParseJob(const string& text, OpRequest& r, wstring& localAppData, wstring& else if (k == "experimental") r.experimental = Truthy(kv.second); else if (k == "force") r.force = Truthy(kv.second); else if (k == "noscan") r.noScan = Truthy(kv.second); + else if (k == "moveplugins") r.movePlugins = Truthy(kv.second); else if (k == "optireset") r.optiReset = Truthy(kv.second); else if (k == "optikeep") r.optiKeep = Truthy(kv.second); else if (k == "optionly") r.optiOnly = Truthy(kv.second); diff --git a/clean/installer/src/wg_core/launcher.h b/clean/installer/src/wg_core/launcher.h index 7612e582..b015067a 100644 --- a/clean/installer/src/wg_core/launcher.h +++ b/clean/installer/src/wg_core/launcher.h @@ -104,6 +104,7 @@ struct GameEntry { std::vector coexist; // the rules table for this game (design section 5) ProxyChoice proxyPlan; // where OptiScaler would go (not installed yet) or stays std::vector leftovers; // WrongGPU files without a record (status Leftovers) + bool leftoversOtherSetup = false; // 0.6.1: ...used by another mod's setup (LeftoversUsedByOtherSetup): left alone, no Leftovers status LastRun last; wstring proxy; // OptiScaler's proxy DLL of our install // Ray Reconstruction (rr.h): only games that use it show anything of it @@ -173,6 +174,7 @@ struct OpRequest { wstring optiPackage; // install/update/repair: the player's OptiScaler download wstring modelDll; // a DLSS model file to try first bool moveMods = false, removeOld = false, experimental = false, force = false, noScan = true; + bool movePlugins = false; // 0.6.1: other setups' OptiScaler plugins moved aside with the player's OK (WrongGPU's RR then goes in) bool hasProfile = false; // apply: this profile (else the game's profile.ini); install: the profile a new install starts with Profile profile; // apply, the OptiScaler tab: edits of editable keys ("Section.Key", value); reset: the editable keys back to what the diff --git a/clean/installer/src/wg_core/leftovers.cpp b/clean/installer/src/wg_core/leftovers.cpp index 1f219d39..7f65a8e5 100644 --- a/clean/installer/src/wg_core/leftovers.cpp +++ b/clean/installer/src/wg_core/leftovers.cpp @@ -20,13 +20,16 @@ struct KnownSet { KnownSet KnownFiles(Context& ctx) { KnownSet k; for (auto& f : kKnownFiles) { k.byHash.emplace(Lower(f.sha256), Known{f.version, f.name}); k.sizes.insert(f.size); } - if (ctx.data) - for (auto& f : *ctx.data) { - const wstring rel = f.rel; - if (!EndsWithI(rel, L".dll") && !EndsWithI(rel, L".asi") && !StartsWithI(BaseName(rel), L"wronggpu-")) continue; - k.byHash.emplace(Lower(f.sha256), Known{ctx.data->version, BaseName(rel)}); - k.sizes.insert(f.size); - } + auto add = [&](const PayloadFile& f) { + const wstring rel = f.rel; + if (!EndsWithI(rel, L".dll") && !EndsWithI(rel, L".asi") && !StartsWithI(BaseName(rel), L"wronggpu-")) return; + k.byHash.emplace(Lower(f.sha256), Known{ctx.data->version, BaseName(rel)}); + k.sizes.insert(f.size); + }; + if (ctx.data) { + for (auto& f : *ctx.data) add(f); + for (size_t i = 0; i < ctx.data->rrCount; ++i) add(ctx.data->rrFiles[i]); // 0.6.1: the RR plugin builds too (WrongGPU-RR.asi) + } return k; } } // namespace @@ -35,6 +38,11 @@ KnownSet KnownFiles(Context& ctx) { static const wchar_t* const kDirectCompanions[] = {L"wronggpu.ini", L"wronggpu-fsr.log", L"wronggpu-fsr.log.old", L"wronggpu-license.txt", L"wronggpu-notices.txt"}; +bool KnownReleaseFile(Context& ctx, const wstring& path) { + const KnownSet k = KnownFiles(ctx); + return IsFile(path) && k.sizes.count(FileSize(path)) && k.byHash.count(Lower(Sha256File(path))); +} + bool ProvablyOurs(Context& ctx, const wstring& path) { const Fingerprint f = IdentifyFile(path); if (f.tool == Tool::WrongGPU && f.evidence.rfind(L"version resource", 0) == 0) return true; @@ -122,6 +130,15 @@ std::vector FindLeftovers(Context& ctx, const wstring& dir) { return out; } +bool LeftoversUsedByOtherSetup(const wstring& dir, const std::vector& files) { + if (files.empty() || dir.empty() || IsFile(RecordPath(dir)) || !FindConflicts(dir, dir).modsFound()) return false; + // WrongGPU's own setup that lost its record: a file only the launcher installs is among them (the menu plugin, or the + // licence under its payload name); the integration kit ships neither under these names + for (auto& f : files) + if (IEq(f.rel, kAsiPlugin) || IEq(f.rel, Join(kAsiPluginOwnDir, BaseName(kAsiPlugin))) || IEq(f.rel, L"wronggpu-license.txt")) return false; + return true; +} + wstring LeftoverSummary(const std::vector& files) { if (files.empty()) return L""; std::map versions; diff --git a/clean/installer/src/wg_core/leftovers.h b/clean/installer/src/wg_core/leftovers.h index b47fa320..0fc87cb3 100644 --- a/clean/installer/src/wg_core/leftovers.h +++ b/clean/installer/src/wg_core/leftovers.h @@ -23,6 +23,14 @@ struct Leftover { wstring rel, sha, version, abs; }; // DLL (the one case that goes by name). Empty when `dir` has an install record. std::vector FindLeftovers(Context& ctx, const wstring& dir); wstring LeftoverSummary(const std::vector& files); // "3 files of WrongGPU 0.4.5 (wronggpu_runtime.dll, ...)" +// 0.6.1: an OptiScaler that WrongGPU didn't install is next to them (its marker files, or a DLL a game loads by name whose +// fingerprint is OptiScaler; there is no install record): another mod's setup that uses WrongGPU's files (its integration +// kit). They are "used by another mod's setup" and left alone by default: no Leftovers status, Clean up and Adopt only when +// confirmed, an install backs up any it replaces (put back on uninstall) instead of removing them first. Not when `files` +// hold one only WrongGPU's launcher installs (plugins\WrongGPU.asi, wronggpu-license.txt; the integration kit ships neither +// under those names): that is WrongGPU's own OptiScaler setup that lost its record, and the OptiScaler is its own. +bool LeftoversUsedByOtherSetup(const wstring& dir, const std::vector& files); +const wchar_t* const kLeftoversOtherSetup = L"used by another mod's setup (an OptiScaler that WrongGPU didn't install is next to them)"; // Clean up: each file's hash is checked again right before it is removed; anything else stays. A FidelityFX DLL of ours // in an engine plugin folder is removed only when the game's own DLL (kept as .wronggpu-original.dll) is there to // put back; otherwise it stays and a note says why. Returns notes. @@ -33,5 +41,9 @@ std::vector AdoptLeftovers(Context& ctx, const wstring& exe, const wstr // A file that is provably a WrongGPU build although the record names another hash (a newer build placed by hand): its // version resource says WrongGPU, or its hash is one of our releases' or the embedded payload's. Never by its name. bool ProvablyOurs(Context& ctx, const wstring& path); +// 0.6.1: the file's hash is one of WrongGPU's releases' (known_releases.h) or of the payload this program embeds. What the +// uninstall removes although the record names another hash goes by this only, never by a version resource (another setup's +// build may name WrongGPU). +bool KnownReleaseFile(Context& ctx, const wstring& path); } // namespace wg diff --git a/clean/installer/src/wg_core/logtail.cpp b/clean/installer/src/wg_core/logtail.cpp index 6135fd76..baab2ddf 100644 --- a/clean/installer/src/wg_core/logtail.cpp +++ b/clean/installer/src/wg_core/logtail.cpp @@ -2,6 +2,8 @@ // WrongGPU launcher core: "Last run" from wronggpu-fsr.log (logtail.h). Written for this project. #include "logtail.h" +#include + #include "gamerules.h" #include "optiscaler.h" @@ -203,7 +205,8 @@ wstring LastRun::Summary() const { else if (upscaler == L"network" && !created) s = L"WrongGPU not used (the game asked for no upscaler)"; else if (upscaler == L"network") s = L"Model M did not start"; else s = L"started" + (upscaler.empty() ? wstring() : L" (" + upscaler + L")"); - if ((rrOnly && upscaler.empty()) || rrUpscaled) // a Ray Reconstruction session alone (r4 #1), or RR upscaling where Model M didn't (r6 #1) + if (rrGuardOff && upscaler.empty()) s = L"Ray Reconstruction: WrongGPU RR stayed off"; // 0.6.1: its guard (Last run says why) + else if ((rrOnly && upscaler.empty()) || rrUpscaled) // a Ray Reconstruction session alone (r4 #1), or RR upscaling where Model M didn't (r6 #1) s = rrFrames <= 0 ? wstring(L"Ray Reconstruction: no successful frame") // an attempt without one (r6 #2) : L"Ray Reconstruction" + (rrMs.empty() ? wstring() : L" (" + rrMs + L" ms a frame)"); if (!support.empty()) s += L" \u00b7 " + support; @@ -240,7 +243,8 @@ void ParseRrLog(const string& text, LastRun& r) { // a long session: its "attached" line has scrolled out of the log's tail (ReadTail keeps 256 KB) while its instance // and timing lines are still there; with no other load line in the tail, the whole tail is that session if (text.find("load: process ") != string::npos || - (text.find("runtime: create instance") == string::npos && text.find(" ms per frame") == string::npos)) + (text.find("runtime: create instance") == string::npos && text.find(" ms per frame") == string::npos && + std::none_of(std::begin(kRrGuardLines), std::end(kRrGuardLines), [&](const char* g) { return text.find(g) != string::npos; }))) return; start = 0; } @@ -281,6 +285,14 @@ void ParseRrLog(const string& text, LastRun& r) { r.rrNote = L"the game's request was refused (" + why(b.substr(nr + kRefused.size())) + L")"; } if (b.find("colour passed through, success reported") != string::npos) r.rrPassThrough = true; + // 0.6.1: the plugin's coexistence guard (another RR plugin, a second copy of WrongGPU RR, hooks replaced): its line from + // the sentence on (the last one; its whole text up to 400 characters: the lines run to about 250) + for (const char* g : kRrGuardLines) + if (const size_t gp = b.find(g); gp != string::npos) { + const string line = b.substr(gp); + r.rrGuard = FromUtf8(line.size() > 400 ? line.substr(0, 397) + "..." : line); + break; + } // the mode: an Exact the plugin refused runs Accurate; a switch "rr_mode accurate -> fast"; "rr_mode=fast", "rr_mode fast" if (b.find("using accurate") != string::npos || b.find("accurate runs") != string::npos) r.rrMode = L"accurate"; else if (const size_t arrow = b.find(" -> "); arrow != string::npos && b.find("rr_mode ") != string::npos && b.find("rr_mode ") < arrow) { @@ -376,7 +388,8 @@ bool CountRrRun(LastRun& r) { // Requiem) run Ray Reconstruction only, and the front end writes no log there. An attempt counts whether or not a frame // succeeded (r6 #2: a failed one is a run that says so, never "Not played yet" or an older run's success); "upscaled" is RR // frames evaluated successfully (r5 #1) - if (!r.rrFound || !r.rrUsed) return false; + // 0.6.1: a session whose guard kept WrongGPU RR off (rrGuard) is a run too: Last run says why + if (!r.rrFound || (!r.rrUsed && r.rrGuard.empty())) return false; // the same game session in the front end's log too (r5 #3): its own evidence stays as it is (created: the game asked for // Model M; upscaled: Model M upscaled a frame), so the page never says Model M worked, or failed, on RR's frames; RR's // frames show on the Denoiser row. Where Model M upscaled none, RR did the upscaling (it denoises and upscales in one pass, @@ -388,11 +401,27 @@ bool CountRrRun(LastRun& r) { return true; } r.rrOnly = true; - r.found = r.created = true; + r.found = true; + r.created = r.rrUsed; // (a guard session alone: the game's request never reached WrongGPU RR) + r.rrGuardOff = !r.rrUsed && !r.rrGuard.empty(); r.upscaled = r.rrFrames > 0; return true; } +wstring LastRunCacheFlags(const LastRun& r) { + auto bit = [](bool b) { return b ? L'1' : L'0'; }; + return {bit(r.found), bit(r.ready), bit(r.optiPlugin), bit(r.upscaled), bit(r.rrOnly), bit(r.rrUpscaled), bit(r.rrGuardOff)}; +} +bool ReadLastRunCacheFlags(const wstring& f, LastRun& r) { + if (f.size() != 3 && f.size() != 5 && f.size() != 6 && f.size() != 7) return false; // (3: before r4; 5: before r6; 6: before 0.6.1) + for (wchar_t c : f) if (c != L'0' && c != L'1') return false; + r.found = f[0] == L'1'; r.ready = f[1] == L'1'; r.optiPlugin = f[2] == L'1'; + if (f.size() >= 5) { r.upscaled = f[3] == L'1'; r.rrOnly = f[4] == L'1'; } + if (f.size() >= 6) r.rrUpscaled = f[5] == L'1'; + if (f.size() >= 7) r.rrGuardOff = f[6] == L'1'; + return true; +} + wstring RrLogPath(const wstring& installDir) { const wstring here = Join(installDir, L"wronggpu-rr.log"), mirrored = Join(Join(installDir, kMirrorDir), L"wronggpu-rr.log"); WIN32_FILE_ATTRIBUTE_DATA a{}, b{}; @@ -431,7 +460,8 @@ RrJoin JoinRrSession(const SessionSpan& front, const SessionSpan& rr) { // The RR session's evidence into the run (the same game session, or the RR session alone) static void TakeRr(LastRun& r, const LastRun& rr) { r.rrFound = rr.rrFound; r.rrUsed = rr.rrUsed; r.rrMode = rr.rrMode; r.rrMs = rr.rrMs; r.rrFrames = rr.rrFrames; r.rrClock = rr.rrClock; - r.rrNote = rr.rrNote; r.rrPassThrough = rr.rrPassThrough; + r.rrNote = rr.rrNote; r.rrPassThrough = rr.rrPassThrough; r.rrGuard = rr.rrGuard; + if (!rr.rrGuard.empty()) r.warnings.push_back({L"rr-guard", rr.rrGuard}); // 0.6.1: the RR plugin's guard line, shown in Last run if (r.renderSize.empty() && r.outputSize.empty()) { r.renderSize = rr.renderSize; r.outputSize = rr.outputSize; } // (an RR-only run's sizes) } @@ -458,7 +488,7 @@ LastRun ReadLastRun(const wstring& installDir) { if (rr.rrFound) { const RrJoin join = !have || !r.found ? RrJoin::RrNewer : JoinRrSession(SpanOf(r.clock, wt), SpanOf(rr.rrClock, rwt)); if (join == RrJoin::Same || (join == RrJoin::RrNewer && !(have && r.found))) TakeRr(r, rr); - else if (join == RrJoin::RrNewer && rr.rrUsed) { r = LastRun(); TakeRr(r, rr); have = false; } + else if (join == RrJoin::RrNewer && (rr.rrUsed || !rr.rrGuard.empty())) { r = LastRun(); TakeRr(r, rr); have = false; } } r.plugin = asi.plugin; for (auto& w : asi.warnings) r.warnings.push_back(w); diff --git a/clean/installer/src/wg_core/logtail.h b/clean/installer/src/wg_core/logtail.h index 02f997f5..f96605d6 100644 --- a/clean/installer/src/wg_core/logtail.h +++ b/clean/installer/src/wg_core/logtail.h @@ -32,7 +32,7 @@ struct LastRun { wstring support; // the last [support] WG-... code wstring renderSize, outputSize; // the last "WrongGPU frame:" line's R=WxH and O=WxH (the window's stat tiles) wstring plugin; // WrongGPU.asi: "hooked", "not-hooked" (wronggpu-asi.log), empty without its log - struct Warning { wstring kind, text; }; // kind: foreign-vtable, no-depth, xess-no-depth, plugin-not-hooked + struct Warning { wstring kind, text; }; // kind: foreign-vtable, no-depth, xess-no-depth, plugin-not-hooked, rr-guard std::vector warnings; // Ray Reconstruction (wronggpu-rr.log, the RR plugin's log next to the exe; its last session) bool rrFound = false; // the RR plugin's log has a session @@ -49,6 +49,13 @@ struct LastRun { wstring rrNote; // the RR log's last failure reason (r6 #2): the runtime's "evaluate failed before any pass: " or // "create: failed ()", or the direct route's "RR feature refused (...): " (r7 #3); empty without one bool rrPassThrough = false; // the plugin passed the game's colour through for a failed evaluate ("colour passed through") + // 0.6.1: the RR plugin's coexistence guard line in that session (kRrGuardLines; clean/rr_f/proxy/HOOK-MODE.md, "Another Ray + // Reconstruction plugin"), from its sentence on: WrongGPU RR stayed off, or was replaced, in that run. The last one; empty + // without one. Last run shows it (warning kind "rr-guard"); an RR-only session with one is a run that says so + wstring rrGuard; + // ...and the run is that RR-only session alone, where the guard kept WrongGPU RR off (no RR request reached it; CountRrRun): + // no Ray Reconstruction in it, whatever the RR setup. Kept in the game list's startup cache (LastRunCacheFlags) + bool rrGuardOff = false; // A session of the RR plugin where the game asked for RR counts as a run (r4 #1: Borderlands 4, Hogwarts Legacy and RE Requiem // run Ray Reconstruction only, so the front end writes no log there; r6 #2: an attempt counts whether or not a frame succeeded): // without a front-end session ReadLastRun sets found and created for it, and upscaled only with frames evaluated ("upscaled" for @@ -70,7 +77,15 @@ struct LastRun { // WrongGPU upscaled frames in the run: Model M's own frames (upscaled; for an RR-only run its RR frames), or Ray Reconstruction's // in one session with the front end where Model M upscaled none (rrUpscaled, r6 #1). The checklist and the header's Worked test bool AnyUpscaled() const { return found && (upscaled || rrUpscaled); } + // Ray Reconstruction alone in the run (r4 #1, r6 #1): an RR-only run, or RR upscaling where Model M didn't; never a run whose + // guard kept WrongGPU RR off (0.6.1) + bool RrAlone() const { return found && ((rrOnly && !rrGuardOff) || rrUpscaled); } }; +// 0.6.1: the last run in the game list's startup cache (library-list.txt, ui_library.cpp): its flags as 0 / 1 characters (found, +// ready, optiPlugin, upscaled, rrOnly, rrUpscaled, rrGuardOff) and, in a field of its own, the guard line (rrGuard). Read back: +// 3, 5, 6 or 7 characters (lists of earlier builds); false for anything else. +wstring LastRunCacheFlags(const LastRun& r); +bool ReadLastRunCacheFlags(const wstring& flags, LastRun& r); // A log's last session on the PC's local clock (seconds): its process id, its start and its end. From the times of day the log // has, on the day of the file's last write (the day before when the last one is later than the write: a copied log). @@ -106,6 +121,13 @@ void ParseAsiLog(const string& text, LastRun& r); // a switch in OptiScaler's menu or in the runtime), the last timing line's GPU time a frame. A session whose "attached" line has // scrolled out of the tail (no other load line in it, but its instance or timing lines): the whole tail. void ParseRrLog(const string& text, LastRun& r); +// 0.6.1: the beginnings of the RR plugin's guard lines where WrongGPU RR stays off (clean/rr_f/proxy/HOOK-MODE.md at +// the RR guard, "Log lines"; each right after the log's time stamp), matched in a line of its session. Never +// the take mode's "another Ray Reconstruction plugin is active; rr_other_plugin=take: WrongGPU RR goes in front of it (": +// WrongGPU RR is on there. +inline const char* const kRrGuardLines[] = {"another Ray Reconstruction plugin is active; WrongGPU RR stays off (", + "a second copy of WrongGPU RR is loaded (", + "a plugin loaded after WrongGPU replaced its hooks; rr_other_plugin=take cannot be applied"}; // OptiScaler.log names XeSS as the game's upscaler input (only used to name the cause of a "no depth" warning). bool OptiLogMentionsXess(const string& text); // Reads the last 256 KB of \wronggpu-fsr.log, the plugin's log (next to OptiScaler or in its own folder), the RR diff --git a/clean/installer/src/wg_core/record.cpp b/clean/installer/src/wg_core/record.cpp index 30eff7d3..0746aa74 100644 --- a/clean/installer/src/wg_core/record.cpp +++ b/clean/installer/src/wg_core/record.cpp @@ -6,6 +6,7 @@ #include #include "detect.h" +#include "fingerprint.h" #include "gamerules.h" #include "json_writer.h" #include "launcher.h" @@ -14,6 +15,7 @@ #include "payload.h" #include "rr.h" #include "rrconfig.h" +#include "settings.h" namespace wg { @@ -190,6 +192,22 @@ wstring Target(const wstring& dir, const wstring& rel) { // A record of this route: its OptiScaler was put there by this installer, and the logs that OptiScaler writes while the // game runs belong to the install (removed with it, never "another mod"). bool HostedRecord(const Record& m) { for (auto& e : m.e) if (e.action == L"copy" && IEq(e.rel, L"OptiScaler.ini")) return true; return false; } +bool OptiIniIsOurs(const wstring& dir, const Record& m) { + string text, v; + if (!ReadAll(Join(dir, L"OptiScaler.ini"), text)) return false; + auto trimmed = [](string s) { + const char* const ws = " \t\r\n\""; + const size_t a = s.find_first_not_of(ws), z = s.find_last_not_of(ws); + return a == string::npos ? string() : s.substr(a, z - a + 1); + }; + if (RecordCopies(m, kOptiSlotFrontEnd)) return IniHasKey(text, "Upscalers", "Dx12Upscaler", &v) && IEq(FromUtf8(trimmed(v)), L"WrongGPU"); + if (RecordCopies(m, kOptiFrontEnd)) { + if (!IniHasKey(text, "Libraries", "FfxDx12SRPath", &v)) return false; + const wstring path = FromUtf8(trimmed(v)); + return !path.empty() && IEq(FullPath(path), FullPath(Join(dir, kOptiFrontEnd))); + } + return true; +} // ------------------------------------------------------------------------------------------------ // Uninstall registration (one entry per game) @@ -380,7 +398,7 @@ void StartCleanup(Context& ctx, const wstring& state, const wstring& self, const } } -std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool failedInstall, bool keepState) { +std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool failedInstall, bool keepState, std::map* keptWarnings) { Record m; if (!LoadRecord(RecordPath(dir), m) || m.legacy) Fail(L"No WrongGPU installation record was found in " + dir + L".", EXIT_NOT_INSTALLED); if (!IEq(m.game, dir)) Fail(L"The installation record belongs to a different folder: " + m.game); @@ -405,7 +423,17 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa if (!Exists(b) || Sha256File(b) != e.orig) { // The game's FSR DLL is in the folder a second time, next to WrongGPU's: that copy will do. const wstring kept = sl ? Target(dir, sl->original) : wstring(); - if (kept.empty() || Sha256File(kept) != e.orig) Fail(L"The backup of " + e.rel + L" is missing or damaged. Nothing was changed."); + const bool keptOk = !kept.empty() && Sha256File(kept) == e.orig; + // 0.6.1: an uninstall never takes a game FSR DLL away without the game's original to put back (neither + // the backup nor the kept copy): the file under the game's name stays, with a warning, and the rest of + // the install goes. An update or repair still stops here (record and backup stay for the next try). + if (!keptOk && sl && !keepState) { + skip.insert(i); + warnings.push_back(L"Left in place: " + e.rel + L" (WrongGPU's file under the game's name: the game's own " + e.rel + + L" isn't in the backup to put back). Verify the game's files in your store to get it back."); + continue; + } + if (!keptOk) Fail(L"The backup of " + e.rel + L" is missing or damaged. Nothing was changed."); from[i] = kept; } } @@ -421,23 +449,34 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa continue; } // rc6 L5: the OptiScaler.ini of this install's OptiScaler setup, saved by OptiScaler's own menu: the - // install's all the same (removed with it; a player's file it replaced comes back from the backup) - if (e.action == L"copy" && IEq(e.rel, L"OptiScaler.ini")) { + // install's all the same (removed with it; a player's file it replaced comes back from the backup). + // 0.6.1: only while its keys still point at WrongGPU's files (OptiIniIsOurs); else it is another + // setup's: left in place with a warning (an update replaces it only with the switch question's OK, + // and then backs it up) + if (e.action == L"copy" && IEq(e.rel, L"OptiScaler.ini") && OptiIniIsOurs(dir, m)) { ui.log(L"OptiScaler.ini was saved by OptiScaler's menu since the install: " + wstring(e.existed ? L"the file that was there before is put back" : L"removed with the rest")); continue; } - // Changed since install, but WrongGPU's own all the same (a newer build placed by hand): an FSR - // DLL by its version resource, the rest of the payload by its name (the settings file is the - // player's). It goes like the file the record names, and the game's original comes back. + // Changed since install, but WrongGPU's own all the same: an FSR DLL of a direct install by its + // version resource (the game's original comes back in its place), any other file only when its + // hash is one of WrongGPU's releases or of this build's payload (0.6.1: never by a version + // resource; another setup's build may name WrongGPU, and is left in place). The settings file is + // the player's. if (e.action == L"copy" && (sl ? ClassifySlot(*sl, t, nullptr, info) == FFX_OURS - : !EndsWithI(e.rel, L".ini") && ProvablyOurs(ctx, t))) { - ui.log(e.rel + L" is not the file that was installed, but it is WrongGPU's own" + (sl ? L" (" + info + L")" : wstring()) + L": removed with the rest"); + : !EndsWithI(e.rel, L".ini") && KnownReleaseFile(ctx, t))) { + ui.log(e.rel + L" is not the file that was installed, but it is WrongGPU's own" + (sl ? L" (" + info + L")" : wstring(L" (a release's file)")) + L": removed with the rest"); continue; } skip.insert(i); + // 0.6.1: another tool's file there now (another setup's OptiScaler over WrongGPU's proxy) is named as such + const Fingerprint fp = e.action == L"copy" && !IsSlotName(e.rel) ? IdentifyFile(t) : Fingerprint(); warnings.push_back(e.action == L"copy" && IsSlotName(e.rel) ? L"The game replaced " + e.rel + L" (probably an update); its new file was kept." - : L"Left in place (changed since install): " + e.rel); + : e.action == L"copy" && IEq(e.rel, L"OptiScaler.ini") + ? L"Left in place: OptiScaler.ini no longer points at WrongGPU's files (another setup changed it), so it was not removed." + : fp.tool == Tool::OptiScaler ? L"Left in place: " + e.rel + L" is now another setup's OptiScaler (not the file WrongGPU installed)." + : L"Left in place (changed since install): " + e.rel); + if (keptWarnings) (*keptWarnings)[Lower(e.rel)] = warnings.back(); } } } @@ -501,6 +540,21 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa if (m.e[k].action == L"dir" && !skip.count(k) && IsDir(Target(dir, m.e[k].rel)) && RemoveDirectoryW(Target(dir, m.e[k].rel).c_str())) ui.log(L"removed folder " + m.e[k].rel); } + // 0.6.1: an OptiScaler.ini that stays after the uninstall (another setup's) and names WrongGPU's files: that setup uses + // them and may stop working now that WrongGPU's copies are gone + if (!failedInstall && !keepState) { + const wstring exeDir = m.exe.empty() ? dir : Parent(m.exe); + std::set seen; + for (const wstring& d : {dir, exeDir, Join(exeDir, L"OptiScaler")}) { + const wstring p = Join(d, L"OptiScaler.ini"); + string text; + if (!seen.insert(Lower(FullPath(p))).second || !ReadAll(p, text)) continue; + for (auto& c : text) c = (char)tolower((unsigned char)c); + if (text.find("wronggpu") == string::npos) continue; + const wstring shown = p.size() > dir.size() + 1 && StartsWithI(p, dir + L"\\") ? p.substr(dir.size() + 1) : p; + warnings.push_back(L"Another setup's " + shown + L" still names WrongGPU's files: that setup may need them, and WrongGPU's copies were removed with it."); + } + } // the game's Engine.ini outside the game folder (rrconfig.h, rr_config_fix=on): its line taken out again if (!failedInstall && !keepState && m.rrconfig.present) { std::vector notes; diff --git a/clean/installer/src/wg_core/record.h b/clean/installer/src/wg_core/record.h index 66b717b5..53be9d1c 100644 --- a/clean/installer/src/wg_core/record.h +++ b/clean/installer/src/wg_core/record.h @@ -108,6 +108,11 @@ void SaveRecord(const wstring& path, const Record& m); bool SaveRebasedRecord(Context& ctx, const wstring& dir, Record& m); wstring Target(const wstring& dir, const wstring& rel); bool HostedRecord(const Record& m); +// 0.6.1: the OptiScaler.ini in `dir` is still the one of WrongGPU's setup: its keys point at WrongGPU's files (FfxDx12SRPath +// at WrongGPU's front end, or Dx12Upscaler at WrongGPU's custom upscaler slot, whichever the record installed). OptiScaler's +// menu saving it keeps them; a file whose keys point elsewhere is another setup's (it replaced or rewrote WrongGPU's): never +// removed or replaced without the player's OK. A record with neither front end: true (nothing to compare). +bool OptiIniIsOurs(const wstring& dir, const Record& m); // The hive the Apps & features entries go to (HKEY_CURRENT_USER unless set: the elevated worker of another account sets // the player's hive, HKEY_USERS\). HKEY UninstallHive(); @@ -135,7 +140,10 @@ void NotePortableLauncher(const wstring& exe); void UnregisterUninstall(const Record& m); size_t RemoveRuntimeFiles(const wstring& dir, const wstring& exeDir, const Record& m, bool settings); void StartCleanup(Context& ctx, const wstring& state, const wstring& self, const wstring& appData); -std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool failedInstall, bool keepState); +// keptWarnings (0.6.1): the warning of each recorded file left in place because it changed since the install, by its path (the +// update path replaces the warning of a file it then moves aside with the player's OK). +std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool failedInstall, bool keepState, + std::map* keptWarnings = nullptr); // rc6 L4: the player's things in the state folder that a failed install or update never removes when they were there before // it: profile.ini (the game's settings), previous\ (the version Roll back goes to) and rr-config\ (the Engine.ini fix's backup). bool StateHasSettings(const wstring& dir); diff --git a/clean/installer/src/wg_core/test_temp_guard.h b/clean/installer/src/wg_core/test_temp_guard.h new file mode 100644 index 00000000..0a235a66 --- /dev/null +++ b/clean/installer/src/wg_core/test_temp_guard.h @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: MIT +// Test builds only: a test program refuses to start when its temp folder is outside the folder the build was configured +// with (CMake WRONGGPU_TEST_TEMP_ROOT -> WG_TEST_TEMP_ROOT; empty: no check), so a test never writes outside it. Checked: +// the TMP and TEMP variables (each when set) and the folder Windows hands out (GetTempPathW). Header only, no wg_core +// dependency (the wizard policy tests use it too). Written for this project. +#pragma once +#include + +#include +#include + +namespace wg_test { + +// path is root or a folder below it: full paths, either slash, any case, never by a bare prefix ("Q:\Root-x" is not below +// "Q:\Root") +inline bool UnderRoot(const std::wstring& path, const std::wstring& root) { + auto full = [](const std::wstring& p) { + wchar_t buf[MAX_PATH * 2] = {}; + const DWORD n = GetFullPathNameW(p.c_str(), MAX_PATH * 2, buf, nullptr); + std::wstring s = n && n < MAX_PATH * 2 ? std::wstring(buf, n) : p; + for (auto& c : s) c = c == L'/' ? L'\\' : (wchar_t)towlower(c); + while (s.size() > 3 && s.back() == L'\\') s.pop_back(); + return s; + }; + if (path.empty() || root.empty()) return false; + const std::wstring p = full(path), r = full(root); + return p == r || (p.size() > r.size() && p.compare(0, r.size(), r) == 0 && (p[r.size()] == L'\\' || r.back() == L'\\')); +} + +// Empty when the temp folder is below root; else why the program refuses. +inline std::wstring TempOutsideRoot(const std::wstring& root) { + if (root.empty()) return std::wstring(); + for (const wchar_t* name : {L"TMP", L"TEMP"}) { + wchar_t v[MAX_PATH * 2] = {}; + const DWORD n = GetEnvironmentVariableW(name, v, MAX_PATH * 2); + if (n && n < MAX_PATH * 2 && !UnderRoot(v, root)) + return std::wstring(L"refused: ") + name + L"=" + v + L" is outside " + root + L" (WRONGGPU_TEST_TEMP_ROOT)"; + } + wchar_t t[MAX_PATH + 1] = {}; + if (!GetTempPathW(MAX_PATH + 1, t) || !UnderRoot(t, root)) + return std::wstring(L"refused: the temp folder ") + t + L" is outside " + root + L" (WRONGGPU_TEST_TEMP_ROOT)"; + return std::wstring(); +} + +#ifdef WG_TEST_TEMP_ROOT +#define WG_TEST_WIDEN2(x) L##x +#define WG_TEST_WIDEN(x) WG_TEST_WIDEN2(x) +inline std::wstring TempGuard() { return TempOutsideRoot(WG_TEST_WIDEN(WG_TEST_TEMP_ROOT)); } +#else +inline std::wstring TempGuard() { return std::wstring(); } +#endif +const int kTempGuardExit = 97; // the exit code of a refused start + +// Writes the refusal to stderr (also from a WIN32 program whose parent gave it one); true when the program must not start. +inline bool TempGuardRefuses() { + const std::wstring why = TempGuard(); + if (why.empty()) return false; + const std::wstring line = why + L"\n"; + const int n = WideCharToMultiByte(CP_UTF8, 0, line.c_str(), (int)line.size(), nullptr, 0, nullptr, nullptr); + std::string u(n > 0 ? n : 0, '\0'); + if (n > 0) WideCharToMultiByte(CP_UTF8, 0, line.c_str(), (int)line.size(), &u[0], n, nullptr, nullptr); + const HANDLE h = GetStdHandle(STD_ERROR_HANDLE); + DWORD done = 0; + if (h && h != INVALID_HANDLE_VALUE) WriteFile(h, u.data(), (DWORD)u.size(), &done, nullptr); + return true; +} + +} // namespace wg_test diff --git a/clean/installer/tests/coexist_061_tests.py b/clean/installer/tests/coexist_061_tests.py new file mode 100644 index 00000000..d0309561 --- /dev/null +++ b/clean/installer/tests/coexist_061_tests.py @@ -0,0 +1,416 @@ +# SPDX-License-Identifier: MIT +"""0.6.1 coexistence fixes (another setup next to WrongGPU's: an OptiScaler that names WrongGPU, other plugins, a changed +OptiScaler.ini, WrongGPU's files in another setup), run by run_coexist_tests.py. + +Written for this project; Python standard library only. Every file of "another setup" is a synthetic stand-in made here +(coexist_fixtures.py / mockpe.py) or a copy of WrongGPU's own files from a test install; no third-party file is read. +""" +import json +import os +import shutil +import subprocess + +import coexist_fixtures as fx +import run_launcher_tests as lt +from run_installer_tests import diff, read, sha, snapshot, write + + +def install(t, exe, opti, *more): + return t.run("install", exe, "--opti=" + opti, "--noscan", "--force", "--experimental", *more) + + +def repair(t, exe, opti, *more): + return t.run("repair", exe, "--opti=" + opti, "--noscan", "--force", *more) + + +def rec_lines(b): + p = os.path.join(b, "wronggpu-setup", "install.record") + return lt.record_text(b).replace("\r", "").split("\n") if os.path.isfile(p) else [] + + +def by_tool(t): + by = {} + for f in t.j.get("coexistence", []): + by.setdefault(f["tool"], []).append(f) + return by + + +def proxy_of(b): + return next((l.split("\t")[1] for l in rec_lines(b) if l.startswith("proxy\t")), "dxgi.dll") + + +def with_files(before, root, files): + """`before` (a snapshot) with these files (relative to root) as they are now.""" + want = dict(before) + now = snapshot(root) + for rel in files: + k = rel.replace("\\", "/").lower() + want[k] = now.get(k) + return want + + +# ---------------------------------------------------------------- fix 1: an OptiScaler that names WrongGPU + +def test_optiscaler_named_wronggpu(t, opti): + print("\n[0.6.1 fix 1] an OptiScaler whose version resource names WrongGPU is an OptiScaler; ours only by the record's name and hash") + d = os.path.join(t.work, "fp061") + shutil.rmtree(d, ignore_errors=True) + files = {"edition-a.dll": (fx.optiscaler_naming_wronggpu(), "optiscaler"), "edition-b.dll": (fx.optiscaler_naming_wronggpu(product_first=False), "optiscaler"), + "plugin.asi": (fx.wronggpu_menu_plugin(), "wronggpu"), "runtime.dll": (fx.wronggpu_runtime_like(), "wronggpu")} + for n, (data, _) in files.items(): + write(os.path.join(d, n), data) + rc = t.run("fingerprint", *[os.path.join(d, n) for n in files]) + got = {os.path.basename(f["file"]): f.get("tool") for f in t.j.get("files", [])} + t.check("fingerprint: an OptiScaler naming WrongGPU (either field) is optiscaler; WrongGPU's own plugin and runtime stay wronggpu", + rc == 0 and all(got.get(n) == k for n, (_, k) in files.items()), got) + shutil.rmtree(d, ignore_errors=True) + + root, b, exe = lt.game(t, "Edition Next Game", validated=True) + before = snapshot(root) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + proxy = proxy_of(b) + other = "winmm.dll" if proxy.lower() != "winmm.dll" else "version.dll" + edition = fx.optiscaler_naming_wronggpu() + write(os.path.join(b, other), edition) # another setup's OptiScaler (it names WrongGPU) beside WrongGPU's + rc2 = t.run("coexist", exe) + by = by_tool(t) + t.check("coexist: the other OptiScaler (names WrongGPU) is not WrongGPU's: ask to switch, WrongGPU's setup still managed", + rc == 0 and rc2 == 0 and any(f["decision"] == "ask-switch" and other in f.get("files", []) for f in by.get("optiscaler", [])) and + any(f["decision"] == "managed" for f in by.get("optiscaler", [])), by.get("optiscaler")) + state = snapshot(root) + rc = repair(t, exe, opti) + t.check("repair without the player's OK: exit 6 (switch asked), nothing changed (never a second OptiScaler beside it)", + rc == 6 and snapshot(root) == state, (rc, t.j.get("message"), diff(state, snapshot(root)))) + rc = repair(t, exe, opti, "--switch") + lines = rec_lines(b) if rc == 0 else [] + t.check("repair --switch: the other OptiScaler moved aside (owner moved, in the backup)", rc == 0 and ("owner\tdisable\t%s\tmoved" % other) in lines and + not os.path.exists(os.path.join(b, other)) and read(os.path.join(b, "wronggpu-setup", "backup", other)) == edition, (rc, t.j.get("message"), lines[:16])) + rc = t.run("uninstall", exe) + want = dict(before) + want[os.path.relpath(os.path.join(b, other), root).replace("\\", "/").lower()] = sha(edition) + t.check("uninstall: the game as before WrongGPU, the other OptiScaler back byte for byte", rc == 0 and snapshot(root) == want, diff(want, snapshot(root))) + + # the same OptiScaler build as WrongGPU's setup (the package's hash) under a name the record does not have: not ours + os.remove(os.path.join(b, other)) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + proxy = proxy_of(b) + same = "version.dll" if proxy.lower() != "version.dll" else "wininet.dll" + shutil.copyfile(os.path.join(b, proxy), os.path.join(b, same)) + rc2 = t.run("coexist", exe) + by = by_tool(t) + t.check("coexist: the package's own OptiScaler build under another name (" + same + ") is another setup's: ask to switch", + rc == 0 and rc2 == 0 and any(f["decision"] == "ask-switch" and same in f.get("files", []) for f in by.get("optiscaler", [])), by.get("optiscaler")) + os.remove(os.path.join(b, same)) + t.run("uninstall", exe) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 3: another setup's OptiScaler over WrongGPU's proxy + +def older_record(b, version="0.5.1"): + p = os.path.join(b, "wronggpu-setup", "install.record") + write(p, "\r\n".join(("version\t" + version) if l.startswith("version\t") else l for l in read(p).decode("utf-8").split("\r\n"))) + + +def test_proxy_replaced(t, opti): + print("\n[0.6.1 fix 3] another setup's OptiScaler replaced WrongGPU's proxy: Repair / Update ask the switch question first") + root, b, exe = lt.game(t, "Proxy Replaced Game", validated=True) + before = snapshot(root) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + proxy = proxy_of(b) + theirs = fx.optiscaler() + write(os.path.join(b, proxy), theirs) # another setup put its OptiScaler under WrongGPU's proxy name + key = os.path.relpath(os.path.join(b, proxy), root).replace("\\", "/").lower() + rc2 = t.run("status", exe) + g = t.j.get("game", {}) + t.check("status: the other OptiScaler under WrongGPU's proxy name is \"Asks first\" (ask-switch)", rc == 0 and rc2 == 0 and + any(f.get("decision") == "ask-switch" and proxy in f.get("files", []) for f in g.get("coexistence", [])), g.get("coexistence")) + t.check("status: that file is listed by one finding only (WrongGPU's setup says its proxy was replaced; item 10)", + sum(1 for f in g.get("coexistence", []) if proxy in f.get("files", [])) == 1 and + any(f.get("decision") == "managed" and "was replaced" in f.get("what", "") for f in g.get("coexistence", [])), g.get("coexistence")) + state = snapshot(root) + rc = repair(t, exe, opti) + t.check("repair without the player's OK: exit 6 (the switch question), nothing changed, the other OptiScaler untouched", + rc == 6 and snapshot(root) == state and "Switch to WrongGPU's OptiScaler setup" in (t.j.get("message") or ""), (rc, t.j.get("message"), diff(state, snapshot(root)))) + rc = repair(t, exe, opti, "--switch") + lines = rec_lines(b) if rc == 0 else [] + warns = t.j.get("warnings", []) + t.check("repair --switch: the other OptiScaler moved aside (owner moved, in the backup), WrongGPU's under a free name", + rc == 0 and ("owner\tdisable\t%s\tmoved" % proxy) in lines and read(os.path.join(b, "wronggpu-setup", "backup", proxy)) == theirs and + proxy_of(b).lower() != proxy.lower(), (rc, t.j.get("message"), lines[:16])) + t.check("repair --switch: the result says it was moved aside with the OK (no \"Left in place\" for it)", + any(w.startswith("Moved aside with your OK: " + proxy) for w in warns) and not any("Left in place" in w and proxy in w for w in warns), warns) + rc = t.run("uninstall", exe) + want = dict(before) + want[key] = sha(theirs) + t.check("uninstall: the game as before WrongGPU, with the other setup's OptiScaler back byte for byte", rc == 0 and snapshot(root) == want, diff(want, snapshot(root))) + + # Update: the same question; an uninstall leaves the other OptiScaler and says what it is + os.remove(os.path.join(b, proxy)) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + proxy = proxy_of(b) + write(os.path.join(b, proxy), theirs) + older_record(b) + state = snapshot(root) + rc2 = t.run("update", exe, "--opti=" + opti, "--noscan", "--force") + t.check("update without the player's OK: exit 6, nothing changed", rc == 0 and rc2 == 6 and snapshot(root) == state, (rc, rc2, t.j.get("message"))) + rc = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall: the other setup's OptiScaler left in place, named as such", rc == 0 and read(os.path.join(b, proxy)) == theirs and + any(("Left in place: %s is now another setup's OptiScaler" % proxy) in w for w in warns), warns) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 4: OptiScaler.ini is ours only while it points at us + +OTHER_SETUP_INI = ("[Upscalers]\r\nDx12Upscaler=xess\r\n[Libraries]\r\nFfxDx12SRPath=C:\\OtherSetup\\upscaler.dll\r\n" + "; another setup's OptiScaler.ini (synthetic)\r\n") + + +def test_opti_ini_ownership(t, opti): + print("\n[0.6.1 fix 4] OptiScaler.ini is WrongGPU's only while its keys point at WrongGPU's files") + root, b, exe = lt.game(t, "Ini Owner Game", validated=True) + before = snapshot(root) + ini_path = os.path.join(b, "OptiScaler.ini") + key = os.path.relpath(ini_path, root).replace("\\", "/").lower() + # OptiScaler's menu saves the ini (WrongGPU's keys kept): still WrongGPU's, removed by the uninstall (rc6 L5) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + write(ini_path, read(ini_path) + b"; saved by OptiScaler's menu\r\n") + rc2 = t.run("uninstall", exe) + t.check("menu-saved OptiScaler.ini (WrongGPU's keys kept): still WrongGPU's, removed with the uninstall", rc == 0 and rc2 == 0 and snapshot(root) == before, + diff(before, snapshot(root))) + # another setup rewrote it (its keys point elsewhere): asked first, backed up, left alone without the OK + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + write(ini_path, OTHER_SETUP_INI) + rc2 = t.run("status", exe) + g = t.j.get("game", {}) + t.check("status: an OptiScaler.ini that points elsewhere is another setup's (ask-switch)", rc == 0 and rc2 == 0 and + any(f.get("decision") == "ask-switch" and "OptiScaler.ini" in f.get("files", []) for f in g.get("coexistence", [])), g.get("coexistence")) + state = snapshot(root) + rc = repair(t, exe, opti) + t.check("repair without the player's OK: exit 6, nothing changed (the other setup's ini kept)", rc == 6 and snapshot(root) == state, (rc, t.j.get("message"))) + rc = repair(t, exe, opti, "--switch") + lines = rec_lines(b) if rc == 0 else [] + warns = t.j.get("warnings", []) + t.check("repair --switch: the other setup's ini backed up (an entry that existed), WrongGPU's in place, said as replaced with the OK", + rc == 0 and any(l.startswith("copy\t1\t") and l.endswith("\tOptiScaler.ini") for l in lines) and + read(os.path.join(b, "wronggpu-setup", "backup", "OptiScaler.ini")) == OTHER_SETUP_INI.encode() and + any(w.startswith("Replaced with your OK: OptiScaler.ini") for w in warns), (rc, t.j.get("message"), warns)) + rc = t.run("uninstall", exe) + want = dict(before) + want[key] = sha(OTHER_SETUP_INI.encode()) + t.check("uninstall: the other setup's OptiScaler.ini back byte for byte", rc == 0 and snapshot(root) == want, diff(want, snapshot(root))) + os.remove(ini_path) + # uninstall with it rewritten: left in place, with a warning + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + write(ini_path, OTHER_SETUP_INI) + rc2 = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall: an OptiScaler.ini another setup rewrote is left in place with a warning", rc == 0 and rc2 == 0 and + read(ini_path) == OTHER_SETUP_INI.encode() and any("OptiScaler.ini no longer points at WrongGPU's files" in w for w in warns), warns) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 5: what the uninstall removes goes by hash + +def test_uninstall_by_hash(t, opti): + print("\n[0.6.1 fix 5] the uninstall removes a changed file only when its hash is one of WrongGPU's releases") + root, b, exe = lt.game(t, "Uninstall Hash Game", validated=True) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + rt, fe = os.path.join(b, "wronggpu_runtime.dll"), os.path.join(b, "wronggpu_ffx_dx12.dll") + named = fx.wronggpu_runtime_like() # another setup's build that names WrongGPU in its version resource (synthetic) + write(rt, named) + rc2 = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall: a changed file whose version resource names WrongGPU (not a release's hash) is left in place with a warning", + rc == 0 and rc2 == 0 and read(rt) == named and not os.path.exists(fe) and any("changed since install" in w and "wronggpu_runtime.dll" in w for w in warns), warns) + os.remove(rt) + # a release's file under another of the record's names: WrongGPU's, removed + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + shutil.copyfile(fe, rt) # the payload's front end (a hash WrongGPU knows) where the runtime was + rc2 = t.run("uninstall", exe) + t.check("uninstall: a changed file whose hash is a WrongGPU build's is removed with the rest", rc == 0 and rc2 == 0 and not os.path.exists(rt), + (rc2, t.j.get("warnings"))) + # another setup's OptiScaler.ini that names WrongGPU's files stays (fix 4) and is warned about + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + ini = "[Libraries]\r\nFfxDx12SRPath=%s\r\n" % os.path.join(b, "OtherSetup", "wronggpu_ffx_dx12.dll") + write(os.path.join(b, "OptiScaler.ini"), ini) + rc2 = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall: another setup's OptiScaler.ini that names WrongGPU's files gets a warning (that setup may need them)", + rc == 0 and rc2 == 0 and any("still names WrongGPU's files" in w for w in warns), warns) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 2: other setups' plugins beside OptiScaler + +# an RR game: the RR model file stand-in alone (a game that creates RR itself, as run_launcher_tests.py's [direct-rr] game) +RR_FILES = {"bin/x64/nvngx_dlssd.dll": b"MZ synthetic stand-in, not a usable RR model file " * 64} + + +def test_other_plugins(t, opti): + print("\n[0.6.1 fix 2] other setups' OptiScaler plugins: WrongGPU's RR stays out by default; moved aside only with the player's OK") + other = fx.unknown("another setup's OptiScaler plugin (synthetic .asi)") + extra = dict(RR_FILES) + extra["bin/x64/plugins/OtherSetup.asi"] = other + root, b, exe = lt.game(t, "Other Plugin Rr Game", extra=extra) + before = snapshot(root) + rc = t.run("coexist", exe) + by = by_tool(t) + t.check("coexist: the other plugin is found (warn: it may hook RR too)", rc == 0 and + any(f["decision"] == "warn" and f.get("files") == ["plugins\\OtherSetup.asi"] for f in by.get("optiscaler-plugin", [])), by.get("optiscaler-plugin")) + rc = install(t, exe, opti) + rec = lt.record_text(b) if rc == 0 else "" + warns = t.j.get("warnings", []) + t.check("install (default): WrongGPU's RR left out with a warning, the other plugin untouched", + rc == 0 and "WrongGPU-RR.asi" not in rec and read(os.path.join(b, "plugins", "OtherSetup.asi")) == other and + any(w.startswith("Other OptiScaler plugins are in this game (plugins\\OtherSetup.asi)") for w in warns), (rc, t.j.get("message"), warns)) + rc = t.run("uninstall", exe) + t.check("...uninstall byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + rc = install(t, exe, opti, "--switch-plugins") + lines = rec_lines(b) if rc == 0 else [] + warns = t.j.get("warnings", []) + t.check("install --switch-plugins: the other plugin moved aside (owner moved, in the backup), WrongGPU's RR plugin in", + rc == 0 and any(l.endswith("\\WrongGPU-RR.asi") and l.startswith("copy\t") for l in lines) and "owner\tdisable\tplugins\\OtherSetup.asi\tmoved" in lines and + not os.path.exists(os.path.join(b, "plugins", "OtherSetup.asi")) and read(os.path.join(b, "wronggpu-setup", "backup", "plugins", "OtherSetup.asi")) == other and + any(w.startswith("Moved aside with your OK: plugins\\OtherSetup.asi") for w in warns), (rc, t.j.get("message"), lines[:20], warns)) + rc = t.run("uninstall", exe) + t.check("...uninstall: the other plugin back byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + # OptiScaler's own plugin folder counts too; a game without RR keeps every plugin beside WrongGPU's (inform only) + write(os.path.join(b, "OptiScaler", "plugins", "Second.asi"), other) + rc = t.run("coexist", exe) + by = by_tool(t) + t.check("coexist: a plugin in OptiScaler\\plugins\\ counts too", rc == 0 and + any("OptiScaler\\plugins\\Second.asi" in f.get("files", []) for f in by.get("optiscaler-plugin", [])), by.get("optiscaler-plugin")) + shutil.rmtree(root, ignore_errors=True) + root, b, exe = lt.game(t, "Other Plugin Plain Game", extra={"bin/x64/plugins/OtherSetup.asi": other}) + before = snapshot(root) + rc = t.run("coexist", exe) + by = by_tool(t) + rc2 = install(t, exe, opti) + t.check("a game without RR: the other plugin is only shown (inform) and stays; WrongGPU's plugin beside it", rc == 0 and rc2 == 0 and + any(f["decision"] == "inform" for f in by.get("optiscaler-plugin", [])) and read(os.path.join(b, "plugins", "OtherSetup.asi")) == other and + os.path.isfile(os.path.join(b, "plugins", "WrongGPU.asi")), (rc2, by.get("optiscaler-plugin"), t.j.get("message"))) + rc = t.run("uninstall", exe) + t.check("...uninstall byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 6: WrongGPU's files in another mod's setup + +def our_files(t, opti): + """WrongGPU's runtime and front end as a hosted install writes them (from a throwaway game).""" + root, b, exe = lt.game(t, "Kit Source") + install(t, exe, opti) + files = {n: read(os.path.join(b, n)) for n in ("wronggpu_runtime.dll", "wronggpu_ffx_dx12.dll")} + t.run("uninstall", exe) + shutil.rmtree(root, ignore_errors=True) + return files + + +def test_leftovers_other_setup(t, opti): + print("\n[0.6.1 fix 6] WrongGPU's files beside an OptiScaler WrongGPU didn't install: used by another mod's setup, left alone") + kit = our_files(t, opti) + extra = {"bin/x64/dxgi.dll": fx.optiscaler(), "bin/x64/OptiScaler.ini": "[Menu]\r\n; another mod's setup (synthetic)\r\n"} + extra.update({"bin/x64/" + n: d for n, d in kit.items()}) + root, b, exe = lt.game(t, "Other Setup Kit Game", extra=extra) + state = snapshot(root) + rc = t.run("status", exe, "--noscan") + g = t.j.get("game", {}) + left = {x["path"] for x in g.get("leftovers", [])} + t.check("status: not \"leftovers\" (the other mod's OptiScaler is asked about); the files listed as used by another mod's setup", + rc == 0 and g.get("status") == "players-optiscaler" and g.get("leftovers_other_setup") is True and set(kit) <= left, (g.get("status"), g.get("leftovers_other_setup"), left)) + for verb in ("clean-leftovers", "adopt-leftovers"): + rc = t.run(verb, exe) + t.check(verb + ": refused without confirming (exit 2), nothing changed, said why", rc == 2 and snapshot(root) == state and + "used by another mod's setup" in (t.j.get("message") or ""), (rc, t.j.get("message"))) + rc = install(t, exe, opti, "--switch") + notes = " ".join(t.j.get("notes", [])) + t.check("install --switch: the files are not removed first (left alone, said in the notes); installed", rc == 0 and "used by another mod's setup" in notes, + (rc, t.j.get("message"), notes)) + rc = t.run("uninstall", exe) + t.check("uninstall: the other mod's setup back byte for byte (its OptiScaler and WrongGPU's files it used)", rc == 0 and snapshot(root) == state, + diff(state, snapshot(root))) + rc = t.run("clean-leftovers", exe, "--force") + t.check("clean-leftovers --force (confirmed): the files go", rc == 0 and not any(os.path.exists(os.path.join(b, n)) for n in kit), (rc, t.j.get("message"))) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 7: WrongGPU's RR plugin is a known leftover + +def test_rr_plugin_leftover(t, opti): + print("\n[0.6.1 fix 7] leftovers: WrongGPU's RR plugin is recognised (by the embedded payload's and the releases' hashes)") + root, b, exe = lt.game(t, "Rr Leftover Game", extra=dict(RR_FILES)) + rc = install(t, exe, opti) + has_rr = os.path.isfile(os.path.join(b, "plugins", "WrongGPU-RR.asi")) + shutil.rmtree(os.path.join(b, "wronggpu-setup")) # the record is lost + for k, v in t.reg_keys().items(): # ... and its Apps & features entry (test root only) + if k.startswith("WrongGPU-") and v.get("InstallLocation", "").lower().startswith(root.lower()): + subprocess.run(["reg", "delete", t.uninstall + "\\" + k, "/f"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + rc2 = t.run("status", exe, "--noscan") + g = t.j.get("game", {}) + left = {x["path"] for x in g.get("leftovers", [])} + t.check("status: leftovers include plugins\\WrongGPU-RR.asi", rc == 0 and has_rr and rc2 == 0 and g.get("status") == "leftovers" and + "plugins\\WrongGPU-RR.asi" in left, (rc, has_rr, g.get("status"), sorted(left))) + rc = t.run("clean-leftovers", exe) + t.check("clean up: the RR plugin goes with the other leftovers", rc == 0 and not os.path.exists(os.path.join(b, "plugins", "WrongGPU-RR.asi")), (rc, t.j.get("message"))) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- item 9: the "stays out" card of another upscaler mod + +def test_stays_out_card(t, opti): + print("\n[0.6.1 item 9] the card of a game with another upscaler mod (never named) reads as a sentence") + root, b, exe = lt.game(t, "Other Mod Card Game", extra={"bin/x64/" + lt.other_mod_keys()[1][0]: "[mock]\r\n"}) # its marker file + dump = os.path.join(t.work, "ui-dump-061.json") + rc = t.run("ui-dump", "--dump=" + dump, "--noscan", "--library=" + os.path.join(t.work, "games")) + try: + d = json.loads(read(dump).decode("utf-8")) + except Exception as e: # noqa: BLE001 + d = {"error": str(e)} + page = next((p for p in d.get("games", []) if p.get("name") == "Other Mod Card Game"), {}) + texts = [c.get("text", "") for c in page.get("controls", [])] + t.check("card: \"Another upscaler mod is in this game. WrongGPU stays out ...\", never \"Not touched is in this game\"", + rc == 0 and any(x.startswith("Another upscaler mod is in this game. WrongGPU stays out") for x in texts) and + not any("ot touched is in this game" in x for x in texts) and not lt.names_other_mod(json.dumps(page)), (rc, texts[:12])) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- fix 3 follow-up: the switch's OK stands for the same files + +def test_repair_after_switch(t, opti): + print("\n[0.6.1 fix 3 follow-up] Repair after a switch: the files moved aside with the OK go aside again; a different file is asked about") + theirs, ini = fx.optiscaler(), "[Menu]\r\nShowFps=true\r\n; the player's\r\n" + root, b, exe = lt.game(t, "Switch Repair Game", validated=True, extra={"bin/x64/winmm.dll": theirs, "bin/x64/OptiScaler.ini": ini}) + before = snapshot(root) + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force", "--switch") + rc2 = repair(t, exe, opti) + lines = rec_lines(b) if rc2 == 0 else [] + t.check("repair without --switch after a switch: done, the player's OptiScaler moved aside again on the earlier OK", + rc == 0 and rc2 == 0 and "owner\tdisable\twinmm.dll\tmoved" in lines and not os.path.exists(os.path.join(b, "winmm.dll")) and + read(os.path.join(b, "wronggpu-setup", "backup", "winmm.dll")) == theirs, (rc, rc2, t.j.get("message"), lines[:16])) + rc = t.run("uninstall", exe) + t.check("...uninstall: the player's OptiScaler and ini back byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + # the switch moved winmm.dll aside; then another file is put under that name: that one is asked about + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force", "--switch") + other = fx.optiscaler_naming_wronggpu() + write(os.path.join(b, "winmm.dll"), other) + state = snapshot(root) + rc2 = repair(t, exe, opti) + t.check("repair without --switch, a different file under the moved name: exit 6 (asked), nothing changed", rc == 0 and rc2 == 6 and snapshot(root) == state, + (rc, rc2, t.j.get("message"), diff(state, snapshot(root)))) + os.remove(os.path.join(b, "winmm.dll")) + t.run("uninstall", exe) + shutil.rmtree(root, ignore_errors=True) + + +def run_all(t, opti, full): + test_optiscaler_named_wronggpu(t, opti) + test_proxy_replaced(t, opti) + test_repair_after_switch(t, opti) + test_opti_ini_ownership(t, opti) + test_uninstall_by_hash(t, opti) + test_other_plugins(t, opti) + test_leftovers_other_setup(t, opti) + test_rr_plugin_leftover(t, opti) + test_stays_out_card(t, opti) diff --git a/clean/installer/tests/coexist_fixtures.py b/clean/installer/tests/coexist_fixtures.py index a41c9d5e..44a6631d 100644 --- a/clean/installer/tests/coexist_fixtures.py +++ b/clean/installer/tests/coexist_fixtures.py @@ -16,6 +16,24 @@ def optiscaler(version=(0, 9, 5, 4)): return mockpe.make_dll({"ProductName": "OptiScaler", "FileDescription": "OptiScaler (synthetic test file)"}, version=version) +def optiscaler_naming_wronggpu(product_first=True): + """0.6.1: an OptiScaler build of another setup whose version resource also names WrongGPU (an edition of it): the + words only, typed here; with product_first False WrongGPU is in its product name and OptiScaler in its description.""" + if product_first: + return mockpe.make_dll({"ProductName": "OptiScaler", "FileDescription": "OptiScaler, WrongGPU edition (synthetic test file)"}, version=(10, 0, 0, 1)) + return mockpe.make_dll({"ProductName": "WrongGPU edition", "FileDescription": "OptiScaler (synthetic test file)"}, version=(10, 0, 0, 1)) + + +def wronggpu_menu_plugin(): + """WrongGPU's own menu plugin's words (clean/fsr/asi/version_asi.rc): a plugin for OptiScaler, not OptiScaler.""" + return mockpe.make_dll({"CompanyName": "WrongGPU project", "ProductName": "WrongGPU", + "FileDescription": "WrongGPU OptiScaler plugin (adds WrongGPU to OptiScaler's upscaler menu)", "OriginalFilename": "WrongGPU.asi"}) + + +def wronggpu_runtime_like(): + return mockpe.make_dll({"CompanyName": "WrongGPU project", "ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime (synthetic)"}) + + def optiscaler_text(): """No version resource: recognised by the text in it (as OptiScaler's builds carry their name).""" return mockpe.make_dll(None, extra=b"synthetic proxy; reads OptiScaler.ini") diff --git a/clean/installer/tests/coexist_tests.cpp b/clean/installer/tests/coexist_tests.cpp index 1b7c478f..8ca2829c 100644 --- a/clean/installer/tests/coexist_tests.cpp +++ b/clean/installer/tests/coexist_tests.cpp @@ -9,9 +9,11 @@ #include "wg_core/coexist.h" #include "wg_core/fingerprint.h" +#include "wg_core/known_releases.h" #include "wg_core/logtail.h" #include "wg_core/optikeys.h" #include "wg_core/record.h" +#include "wg_core/test_temp_guard.h" using namespace wg; @@ -32,10 +34,56 @@ wstring TempFolder() { void Put(const wstring& path, const string& data) { EnsureDir(Parent(path)); WriteFileAtomic(path, data.data(), data.size()); } Tool ToolOf(const string& bytes, const wstring& name = L"") { return IdentifyBytes((const uint8_t*)bytes.data(), bytes.size(), name).tool; } string Utf16(const char* s) { string r; for (; *s; ++s) { r += *s; r += '\0'; } return r; } +// 0.6.1 (gap 4): a minimal PE32+ DLL whose export table names `names` (Microsoft's public PE/COFF documentation, ".edata"; as +// tests/mockpe.py _export_table): never loaded, only read. Every function points at the section start. +void Le(string& b, uint64_t v, int n) { for (int i = 0; i < n; ++i) b += char((v >> (8 * i)) & 0xFF); } +string ExportDll(const std::vector& names) { + const uint32_t sa = 0x1000, fa = 0x200, k = (uint32_t)names.size(); + const uint32_t funcs = sa + 40, nameArr = funcs + 4 * k, ords = nameArr + 4 * k, strs = ords + 2 * k; + string strings = "plugin.asi"; + strings += '\0'; + std::vector nameRva; + for (auto& n : names) { nameRva.push_back(strs + (uint32_t)strings.size()); strings += n; strings += '\0'; } + string sec; + Le(sec, 0, 4); Le(sec, 0, 4); Le(sec, 0, 2); Le(sec, 0, 2); Le(sec, strs, 4); Le(sec, 1, 4); Le(sec, k, 4); Le(sec, k, 4); + Le(sec, funcs, 4); Le(sec, nameArr, 4); Le(sec, ords, 4); + for (uint32_t i = 0; i < k; ++i) Le(sec, sa, 4); + for (uint32_t i = 0; i < k; ++i) Le(sec, nameRva[i], 4); + for (uint32_t i = 0; i < k; ++i) Le(sec, i, 2); + sec += strings; + const uint32_t edSize = (uint32_t)sec.size(); + while (sec.size() % fa) sec += '\0'; + string h = "MZ"; + h.resize(0x3C, '\0'); + Le(h, 0x40, 4); + h += string("PE\0\0", 4); + Le(h, 0x8664, 2); Le(h, 1, 2); Le(h, 0, 4); Le(h, 0, 4); Le(h, 0, 4); Le(h, 240, 2); Le(h, 0x2022, 2); + string opt(240, '\0'); + auto put32 = [&](size_t o, uint32_t v) { for (int i = 0; i < 4; ++i) opt[o + i] = char((v >> (8 * i)) & 0xFF); }; + opt[0] = 0x0B; opt[1] = 0x02; // PE32+ + put32(32, sa); put32(36, fa); put32(56, sa + (uint32_t)sec.size()); put32(60, fa); put32(108, 16); put32(112, sa); put32(116, edSize); + h += opt; + string name = ".edata"; + name.resize(8, '\0'); + h += name; + Le(h, sec.size(), 4); Le(h, sa, 4); Le(h, sec.size(), 4); Le(h, fa, 4); Le(h, 0, 4); Le(h, 0, 4); Le(h, 0, 2); Le(h, 0, 2); Le(h, 0x40000040u, 4); + h.resize(fa, '\0'); + return h + sec; +} +bool Has(const std::vector& v, const wstring& s) { for (auto& x : v) if (IEq(x, s)) return true; return false; } } // namespace int main() { + if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root try { + // ---- 0.6.1 fix 7: the 0.6.0 release's files, the RR plugin among them, are known (known_releases.h) ------------ + { + int rows060 = 0; + bool rrPlugin = false; + for (auto& f : kKnownFiles) + if (!wcscmp(f.version, L"0.6.0")) { ++rows060; rrPlugin = rrPlugin || !wcscmp(f.name, L"plugins\\WrongGPU-RR.asi"); } + require(rows060 >= 5 && rrPlugin, "known_releases.h has 0.6.0's files, its RR plugin among them"); + } // ---- marker scan ------------------------------------------------------------------------------------------- const char* const needles[] = {"reshade", "dxvk", "optiscaler"}; const string text = "xx RESHADE yy" + Utf16("DxVk") + "zz"; @@ -695,6 +743,155 @@ int main() { for (auto& w : all.warnings) { xessWarn |= w.kind == L"xess-no-depth"; plug |= w.kind == L"plugin-not-hooked"; } require(all.found && xessWarn && plug && all.plugin == L"not-hooked", "ReadLastRun: XeSS without depth (OptiScaler.log), the plugin's log in its own folder"); + // ---- 0.6.1 RR follow-up 1: the RR plugin's guard line (HOOK-MODE.md, "Another Ray Reconstruction plugin") in Last run -------- + { + const string head = "21:00:00.000 load: process 4242 attached C:\\Games\\Example\\plugins\\WrongGPU-RR.asi (hook mode)\r\n"; + // the guard's lines as HOOK-MODE.md ("Log lines") gives them, right after the time stamp + const string otherText = "another Ray Reconstruction plugin is active; WrongGPU RR stays off (synthetic detail; nothing patched; " + "rr_other_plugin=take in wronggpu-rr.ini uses WrongGPU's instead)"; + const string other = "21:00:00.100 " + otherText + "\r\n"; + LastRun g1; + ParseRrLog(head + other, g1); + require(g1.rrFound && !g1.rrUsed && g1.rrGuard == FromUtf8(otherText), "RR guard: another RR plugin: its whole line after the time stamp"); + const char* const finals[] = { + "another Ray Reconstruction plugin is active; WrongGPU RR stays off (synthetic detail; it loaded after WrongGPU: WrongGPU passes every call on " + "unchanged; to use WrongGPU RR, move it aside)", + "a second copy of WrongGPU RR is loaded (C:\\Games\\Example\\plugins\\WrongGPU-RR.asi is active); this copy " + "(C:\\Games\\Example\\OptiScaler\\plugins\\Kit.asi) stays off", + "a plugin loaded after WrongGPU replaced its hooks; rr_other_plugin=take cannot be applied: WrongGPU RR stays off and passes every call on " + "unchanged (synthetic detail); move it aside to use WrongGPU RR"}; + for (const char* line : finals) { + LastRun gx; + ParseRrLog(head + "21:00:01.000 " + line + "\r\n", gx); + require(gx.rrGuard == FromUtf8(line), "RR guard: each of the guard's final lines is found, whole"); + } + // take mode (rr_other_plugin=take): WrongGPU RR goes in front of the other plugin and is on: never a guard line + LastRun take; + ParseRrLog(head + "21:00:00.100 another Ray Reconstruction plugin is active; rr_other_plugin=take: WrongGPU RR goes in front of it " + "(synthetic detail; it gets the game's other calls, no RR work)\r\n", take); + require(take.rrFound && take.rrGuard.empty() && !take.rrGuardOff, "RR guard: the take mode's line is not WrongGPU RR off"); + { + const wstring td = Join(dir, L"rr-guard-take"); + Put(Join(td, L"wronggpu-rr.log"), head + "21:00:00.100 another Ray Reconstruction plugin is active; rr_other_plugin=take: WrongGPU RR goes in " + "front of it (synthetic detail)\r\n21:00:30.000 runtime: create instance 1: output 1920x1080, render 960x540\r\n"); + const LastRun tr = ReadLastRun(td); + bool guardWarn = false; + for (auto& w : tr.warnings) guardWarn |= w.kind == L"rr-guard"; + require(tr.found && tr.rrUsed && !tr.rrGuardOff && !guardWarn && tr.Summary().find(L"stayed off") == wstring::npos, + "RR guard: a take-mode run where RR was asked for: an RR run, no guard warning, never \"stayed off\""); + } + LastRun older; + ParseRrLog(head + other + "21:05:00.000 load: process 4343 attached (hook mode)\r\n", older); + require(older.rrFound && older.rrGuard.empty(), "RR guard: an earlier session's guard line is not the last session's"); + LastRun none; + ParseRrLog(head + "21:00:00.100 RR provider registered with the host (plugin interface 5)\r\n", none); + require(none.rrGuard.empty(), "RR guard: none without its line"); + // read as the launcher reads a game's folder: the RR log alone, the guard kept WrongGPU RR off: a run that says why + const wstring gd = Join(dir, L"rr-guard"); + Put(Join(gd, L"wronggpu-rr.log"), head + other); + const LastRun gr = ReadLastRun(gd); + bool shown = false; + for (auto& w : gr.warnings) shown |= w.kind == L"rr-guard" && w.text == g1.rrGuard; + require(gr.found && gr.rrOnly && !gr.rrUsed && !gr.created && shown && !gr.AnyUpscaled() && gr.Summary().rfind(L"Ray Reconstruction: WrongGPU RR stayed off", 0) == 0, + "RR guard: the RR log alone with the guard line: a run (RR-only, nothing upscaled), the guard line among its warnings, the summary says RR stayed off"); + // with RR frames before a later plugin replaced the hooks: the frames count, the guard line shows too + const string replaced = "21:00:30.000 runtime: create instance 1: output 1920x1080, render 960x540\r\n" + "21:01:00.000 runtime: instance 1 timing, 300 frames from frame 1: GPU 2.000 ms per frame (pre 0.010), render 960x540, output 1920x1080\r\n" + "21:01:05.000 a plugin loaded after WrongGPU replaced its hooks; rr_other_plugin=take cannot be applied: WrongGPU RR stays " + "off and passes every call on unchanged (synthetic detail); move it aside to use WrongGPU RR\r\n"; + Put(Join(gd, L"wronggpu-rr.log"), head + replaced); + const LastRun gf = ReadLastRun(gd); + shown = false; + for (auto& w : gf.warnings) shown |= w.kind == L"rr-guard" && w.text.rfind(L"a plugin loaded after WrongGPU replaced its hooks", 0) == 0; + require(gf.found && gf.rrUsed && gf.rrFrames == 300 && gf.upscaled && shown, "RR guard: RR frames and then the hooks replaced: the run's frames, and the guard line"); + Put(Join(gd, L"wronggpu-rr.log"), head + "21:00:00.100 RR provider registered with the host (plugin interface 5)\r\n"); + require(!ReadLastRun(gd).found, "RR guard: no guard line, no RR request: still not a run"); + + // the game list's startup cache (library-list.txt: LastRunCacheFlags, and the guard line in a field of its own): read + // back, the run is the same for the tile and the page from the start (0.6.1) + require(gr.rrGuardOff && !gr.RrAlone() && !gf.rrGuardOff && gf.RrAlone(), + "RR guard: the guard kept WrongGPU RR off: no Ray Reconstruction alone in the run (the banner's words); frames before the hooks were replaced: RR alone"); + auto cached = [](const LastRun& live) { + LastRun c; + require(ReadLastRunCacheFlags(LastRunCacheFlags(live), c), "startup cache: the flags read back"); + c.when = live.when; c.rrGuard = live.rrGuard; // (their own fields of the list) + return c; + }; + const LastRun cg = cached(gr), cf = cached(gf); + require(LastRunCacheFlags(gr) == L"1000101" && cg.found && cg.rrOnly && cg.rrGuardOff && !cg.RrAlone() && cg.rrGuard == gr.rrGuard && + cg.Summary() == gr.Summary() && !cg.AnyUpscaled(), + "startup cache: a guard run read back is still a guard run (flag, line, summary; no RR alone, nothing upscaled)"); + require(!cf.rrGuardOff && cf.RrAlone() && cf.upscaled && cf.rrGuard == gf.rrGuard, "startup cache: RR frames, then the hooks replaced: as it was"); + LastRun old6, bad; + require(ReadLastRunCacheFlags(L"100011", old6) && old6.found && old6.rrOnly && old6.rrUpscaled && !old6.rrGuardOff, + "startup cache: a list of an earlier build (6 flags) is read, without the guard flag"); + require(!ReadLastRunCacheFlags(L"10", bad) && !ReadLastRunCacheFlags(L"10x0101", bad) && !ReadLastRunCacheFlags(L"10001010", bad), + "startup cache: flags of another length or with other characters are not read"); + } + + // ---- 0.6.1 RR follow-up 2 (gap 4): a plugin exporting WrongGPU RR's marker is WrongGPU's own, whatever its name or hash ----- + { + string hdr; + require(ReadAll(Join(FromUtf8(WG_TEST_LOGS), L"..\\..\\..\\rr_f\\proxy\\include\\wg_rr_settings_contract.h"), hdr), "the RR settings contract header is there"); + require(hdr.find(string("#define WG_RR_CONTRACT_EXPORT \"") + kRrContractExport + "\"") != string::npos, + "gap 4: kRrContractExport is the RR plugin's WG_RR_CONTRACT_EXPORT (wg_rr_settings_contract.h)"); + const wstring kitDir = Join(dir, L"kit-game"), x = Join(kitDir, L"Game.exe"); + Put(x, "MZ synthetic game"); + const string kit = ExportDll({"WrongGPU_RrOther", kRrContractExport}), plain = ExportDll({"InitPlugin", "WrongGPU_RrOther"}); + Put(Join(kitDir, L"plugins\\KitRR.asi"), kit); + Put(Join(kitDir, L"OptiScaler\\plugins\\renamed.asi"), kit + "another build of it"); // another name, another hash + Put(Join(kitDir, L"plugins\\Other.asi"), plain); + Put(Join(kitDir, L"plugins\\Words.asi"), string("MZ not a PE file, only the words ") + kRrContractExport); + require(ExportsRrContract(Join(kitDir, L"plugins\\KitRR.asi")) && ExportsRrContract(Join(kitDir, L"OptiScaler\\plugins\\renamed.asi")) && + !ExportsRrContract(Join(kitDir, L"plugins\\Other.asi")) && !ExportsRrContract(Join(kitDir, L"plugins\\Words.asi")) && + !ExportsRrContract(Join(kitDir, L"plugins\\Missing.asi")), + "gap 4: the marker from the PE export table (never its text alone, never a missing file)"); + const auto ourKit = OurPluginsFromOtherPackages(kitDir, nullptr), foreign = ForeignPlugins(kitDir, nullptr); + require(ourKit.size() == 2 && Has(ourKit, L"plugins\\KitRR.asi") && Has(ourKit, L"OptiScaler\\plugins\\renamed.asi"), + "gap 4: both copies are WrongGPU RR from another package"); + require(foreign.size() == 2 && Has(foreign, L"plugins\\Other.asi") && Has(foreign, L"plugins\\Words.asi"), + "gap 4: they are not other setups' plugins (so never moved aside); the others still are"); + Context ctx; + ctx.logFile = Join(dir, L"kit.log"); + const CoexistReport r = AssessCoexistence(ctx, x, kitDir, nullptr); + const Finding* kf = nullptr; + for (auto& f : r.findings) if (f.what == L"WrongGPU RR (from another package)") kf = &f; + require(kf && kf->tool == Tool::WrongGPU && kf->decision == Decision::Inform && kf->files.size() == 2 && + kf->evidence.find(FromUtf8(kRrContractExport)) != wstring::npos, + "gap 4: the rules table shows them as \"WrongGPU RR (from another package)\" (inform, by the export)"); + require(r.foreignPlugins == foreign && !Has(r.foreignPlugins, L"plugins\\KitRR.asi") && IsFile(Join(kitDir, L"plugins\\KitRR.asi")), + "gap 4: the report's other-setup plugins (what an install moves aside with the OK) leave them out"); + // only those copies: an install folder with just WrongGPU RR from another package has no other-setup plugins at all + DeleteFileW(Join(kitDir, L"plugins\\Other.asi").c_str()); + DeleteFileW(Join(kitDir, L"plugins\\Words.asi").c_str()); + require(AssessCoexistence(ctx, x, kitDir, nullptr).foreignPlugins.empty(), "gap 4: only WrongGPU RR copies: nothing for an install to move aside"); + } + + // ---- 0.6.1 RR follow-up 3 (gap 5a): the install folder is not the exe folder: the exe folder's record names its plugins --- + { + const wstring root = Join(dir, L"split-game"), exeDir = Join(root, L"bin\\x64"), x = Join(exeDir, L"Game.exe"); + Put(x, "MZ synthetic game"); + const string rrAsi = "WrongGPU-RR.asi of an earlier install (synthetic)"; + Put(Join(exeDir, L"plugins\\WrongGPU-RR.asi"), rrAsi); + Record rec; + rec.version = L"0.6.0"; rec.format = 2; rec.game = exeDir; rec.exe = x; rec.status = L"experimental"; rec.model = L"m.wgcm"; + Entry ent; ent.action = L"copy"; ent.rel = L"plugins\\WrongGPU-RR.asi"; ent.inst = Sha256Bytes(rrAsi.data(), rrAsi.size()); ent.owner = L"wg"; + rec.e.push_back(ent); + SaveRecord(RecordPath(exeDir), rec); + Context ctx; + ctx.logFile = Join(dir, L"split.log"); + require(AssessCoexistence(ctx, x, root, nullptr).foreignPlugins.empty(), + "gap 5a: install folder above the exe folder: WrongGPU's RR .asi that the exe folder's record installed is not another setup's"); + Put(Join(exeDir, L"plugins\\Other.asi"), "another setup's plugin (synthetic)"); + const auto both = AssessCoexistence(ctx, x, root, nullptr).foreignPlugins; + require(both.size() == 1 && IEq(both[0], L"plugins\\Other.asi"), "gap 5a: ...another setup's plugin there still is"); + // gap 5b's other half: with the record, an RR .asi changed since the install (not the file installed) is not ours + Put(Join(exeDir, L"plugins\\WrongGPU-RR.asi"), rrAsi + " changed"); + require(Has(ForeignPlugins(exeDir, &rec), L"plugins\\WrongGPU-RR.asi"), "gap 5b: an RR .asi that is no longer the installed file is not counted as ours"); + Put(Join(exeDir, L"plugins\\WrongGPU-RR.asi"), rrAsi); + require(!Has(ForeignPlugins(exeDir, &rec), L"plugins\\WrongGPU-RR.asi"), "gap 5b: the installed file with the record: ours"); + } + RemoveTree(dir); std::printf("coexist-core: %d checks passed\n", checks); return 0; diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index 2e647fde..550e6b8c 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -19,6 +19,7 @@ #include "wg_core/pe.h" #include "wg_core/profile.h" #include "wg_core/record.h" +#include "wg_core/test_temp_guard.h" #include "wg_core/rr.h" #include "wg_core/rrconfig.h" #include "wg_core/settings.h" @@ -40,9 +41,62 @@ wstring TempFolder() { return dir; } string OptionsOf(const string& ini) { string v, s; IniGetFrontEnd(ini, "runtime_options", &v, &s); return v; } + +// A minimal PE32+ DLL with a version resource of `strings` and `extra` bytes after it (a port of tests/mockpe.py make_dll +// without exports or imports, from Microsoft's public PE/COFF and VS_VERSIONINFO documentation): never loaded, only read. +void Le(string& b, uint64_t v, int n) { for (int i = 0; i < n; ++i) b += char((v >> (8 * i)) & 0xFF); } +string U16z(const wstring& s) { string r; for (wchar_t c : s) Le(r, (uint16_t)c, 2); Le(r, 0, 2); return r; } +void Pad(string& b, size_t a) { while (b.size() % a) b += '\0'; } +string VNode(const wstring& key, const string& value, bool text, std::vector children = {}) { + string body; + Le(body, 0, 2); Le(body, 0, 2); Le(body, text ? 1 : 0, 2); + body += U16z(key); + Pad(body, 4); + body += value; + if (!children.empty()) { Pad(body, 4); for (auto& c : children) { Pad(c, 4); body += c; } } + string out; + Le(out, body.size(), 2); Le(out, text ? value.size() / 2 : value.size(), 2); + return out + body.substr(4); +} +string MockDll(const std::vector>& strings, const string& extra) { + string fixed; + for (uint32_t v : {0xFEEF04BDu, 0x00010000u, 0x00010000u, 0u, 0x00010000u, 0u, 0x3Fu, 0u, 0x40004u, 2u, 0u, 0u, 0u}) Le(fixed, v, 4); + std::vector entries; + for (auto& s : strings) entries.push_back(VNode(s.first, U16z(s.second), true)); + string tr; Le(tr, 0x409, 2); Le(tr, 1200, 2); + const string vi = VNode(L"VS_VERSION_INFO", fixed, false, + {VNode(L"StringFileInfo", "", false, {VNode(L"040904B0", "", false, entries)}), VNode(L"VarFileInfo", "", false, {VNode(L"Translation", tr, false)})}); + const uint32_t fa = 0x200, sa = 0x1000; + string rsrc; + auto dirHead = [&] { Le(rsrc, 0, 4); Le(rsrc, 0, 4); Le(rsrc, 0, 2); Le(rsrc, 0, 2); Le(rsrc, 0, 2); Le(rsrc, 1, 2); }; + dirHead(); Le(rsrc, 16, 4); Le(rsrc, 0x80000000u | 0x18, 4); + dirHead(); Le(rsrc, 1, 4); Le(rsrc, 0x80000000u | 0x30, 4); + dirHead(); Le(rsrc, 0x409, 4); Le(rsrc, 0x48, 4); + Le(rsrc, sa + 0x58, 4); Le(rsrc, vi.size(), 4); Le(rsrc, 0, 4); Le(rsrc, 0, 4); + rsrc.resize(0x58, '\0'); + rsrc += vi; + const size_t rsrcSize = rsrc.size(); + string content = rsrc; Pad(content, 16); + string raw = content; Pad(raw, fa); + const uint32_t vsize = (uint32_t)content.size(), image = sa + ((vsize + sa - 1) / sa) * sa; + string h = "MZ"; h.resize(0x3C, '\0'); Le(h, 0x40, 4); + h += string("PE\0\0", 4); + Le(h, 0x8664, 2); Le(h, 1, 2); Le(h, 0, 4); Le(h, 0, 4); Le(h, 0, 4); Le(h, 240, 2); Le(h, 0x2022, 2); + Le(h, 0x20B, 2); Le(h, 14, 1); Le(h, 0, 1); Le(h, 0, 4); Le(h, raw.size(), 4); Le(h, 0, 4); Le(h, 0, 4); Le(h, sa, 4); + Le(h, 0x180000000ull, 8); Le(h, sa, 4); Le(h, fa, 4); + for (int v : {6, 0, 0, 0, 6, 0}) Le(h, v, 2); + Le(h, 0, 4); Le(h, image, 4); Le(h, 0x200, 4); Le(h, 0, 4); Le(h, 2, 2); Le(h, 0x160, 2); + Le(h, 0x100000, 8); Le(h, 0x1000, 8); Le(h, 0x100000, 8); Le(h, 0x1000, 8); Le(h, 0, 4); Le(h, 16, 4); + for (int d = 0; d < 16; ++d) { Le(h, d == 2 ? sa : 0, 4); Le(h, d == 2 ? rsrcSize : 0, 4); } + string name = ".rsrc"; name.resize(8, '\0'); + h += name; Le(h, vsize, 4); Le(h, sa, 4); Le(h, raw.size(), 4); Le(h, fa, 4); Le(h, 0, 4); Le(h, 0, 4); Le(h, 0, 2); Le(h, 0, 2); Le(h, 0x40000040u, 4); + h.resize(fa, '\0'); + return h + raw + extra; +} } // namespace int main() { + if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root try { // ---- validation ----------------------------------------------------------------------------------------- string n; wstring why; @@ -252,8 +306,8 @@ int main() { "moved game: the record read from the new folder names it (game, exe), movedFrom the old one"); require(r.inikeys.size() == 1 && r.inikeys[0].ours == ToUtf8(newDir) + "\\plugins" && r.inikeys[0].original == "auto", "moved game: the journal's paths follow"); // another drive letter: only the changed part of the path is replaced - Record d = m; d.game = L"Q:\\Games\\Moved Game"; d.exe = L"Q:\\Games\\Moved Game\\Game.exe"; d.model = L"Q:\\model.wgcm"; - SaveRecord(RecordPath(newDir), d); + Record drive = m; drive.game = L"Q:\\Games\\Moved Game"; drive.exe = L"Q:\\Games\\Moved Game\\Game.exe"; drive.model = L"Q:\\model.wgcm"; + SaveRecord(RecordPath(newDir), drive); Record dr; require(LoadRecord(RecordPath(newDir), dr) && IEq(dr.exe, Join(newDir, L"Game.exe")) && dr.model == L"Q:\\model.wgcm" && dr.inikeys[0].ours == ToUtf8(oldDir) + "\\plugins", "moved game: a drive letter change; the model path and values of other folders stay"); @@ -283,6 +337,88 @@ int main() { try { DoRestore(mc, newDir, quiet, false, false); } catch (const SetupError&) { refused = true; } require(!refused && !IsFile(Join(newDir, L"wronggpu_runtime.dll")) && !IsDir(StateDir(newDir)) && IsFile(Join(newDir, L"Game.exe")), "moved game: the uninstall works in the new folder"); + + // ---- 0.6.1 (b): a hand-placed WrongGPU DLL under the game's FSR name (a direct install) goes only when the game's + // original is there to put back (the backup, or the kept *.wronggpu-original.dll); else it stays, with a warning ---- + { + const FfxSlot& sl = kSlots[0]; + const string orig = "the game's own FidelityFX DLL (synthetic)", installed = "WrongGPU's FSR DLL as installed (synthetic)"; + const string hand = MockDll({{L"CompanyName", L"WrongGPU project"}, {L"ProductName", L"WrongGPU"}, {L"FileDescription", L"WrongGPU front end (synthetic)"}}, + "a newer build placed by hand"); + auto direct = [&](const wstring& name, bool backup, bool keptCopy) { + const wstring d = Join(dir, L"Direct Slot\\" + name); + file(Join(d, L"Game.exe"), "MZ"); + file(Join(d, sl.name), hand); + if (keptCopy) file(Join(d, sl.original), orig); + if (backup) file(BackupPath(d, sl.name), orig); + Record m; m.version = L"0.4.5"; m.game = d; m.exe = Join(d, L"Game.exe"); m.status = L"experimental"; m.model = L"m.wgcm"; + Entry r; r.action = L"rename"; r.rel = sl.original; r.inst = Sha256Bytes(orig.data(), orig.size()); r.owner = L"moved"; m.e.push_back(r); + Entry c; c.action = L"copy"; c.rel = sl.name; c.existed = true; c.orig = r.inst; c.inst = Sha256Bytes(installed.data(), installed.size()); c.owner = L"wg"; + m.e.push_back(c); + SaveRecord(RecordPath(d), m); + return d; + }; + wstring info; + require(ClassifySlot(sl, [&] { const wstring p = Join(dir, L"slot-probe.dll"); file(p, hand); return p; }(), nullptr, info) == FFX_OURS, + "(b): the hand-placed DLL is WrongGPU's by its version resource (the synthetic PE is read)"); + for (int how = 0; how < 2; ++how) { // the original from the backup, then from the kept copy alone + const wstring d = direct(how ? L"Kept Copy" : L"Backup", how == 0, true); + std::vector w; + bool threw = false; + try { w = DoRestore(mc, d, quiet, false, false); } catch (const SetupError&) { threw = true; } + string now; + require(!threw && ReadAll(Join(d, sl.name), now) && now == orig && !IsFile(Join(d, sl.original)) && !IsDir(StateDir(d)), + how ? "(b): no backup, the kept copy there: the hand-placed DLL is replaced by the game's original" + : "(b): the backup there: the hand-placed DLL is replaced by the game's original"); + } + { + const wstring d = direct(L"No Original", false, false); + std::vector w; + bool threw = false; + try { w = DoRestore(mc, d, quiet, false, false); } catch (const SetupError&) { threw = true; } + string now; + bool warned = false; + for (auto& x : w) warned = warned || (x.rfind(L"Left in place: " + wstring(sl.name), 0) == 0 && x.find(L"isn't in the backup") != wstring::npos); + require(!threw && ReadAll(Join(d, sl.name), now) && now == hand && warned && IsFile(Join(d, L"Game.exe")) && !IsFile(RecordPath(d)), + "(b): no original anywhere: the uninstall leaves the DLL under the game's name, with a warning, and removes the rest"); + const wstring u = direct(L"No Original Update", false, false); + threw = false; + try { DoRestore(mc, u, quiet, false, true); } catch (const SetupError&) { threw = true; } + require(threw && ReadAll(Join(u, sl.name), now) && now == hand && IsFile(RecordPath(u)), + "(b): no original anywhere, an update's restore: refused, nothing changed (record kept)"); + } + } + // ---- 0.6.1 RR follow-up 3 (gap 5b): an update that now leaves RR out (the game no longer uses it, or another setup's + // plugin keeps it out) first runs the earlier install's restore with keepState (DoInstall step 2): the earlier RR plugin + // goes with it when it is the file installed; one changed since is left in place with a warning, never removed ---- + { + const string rrAsi = "WrongGPU-RR.asi as installed (synthetic)", rrIni = "rr_mode=accurate\r\n"; + auto earlier = [&](const wstring& name) { + const wstring d = Join(dir, L"RR Update\\" + name); + file(Join(d, L"Game.exe"), "MZ"); + file(Join(d, L"plugins\\WrongGPU-RR.asi"), rrAsi); + file(Join(d, L"wronggpu-rr.ini"), rrIni); + Record m; m.version = L"0.6.0"; m.format = 2; m.game = d; m.exe = Join(d, L"Game.exe"); m.status = L"experimental"; m.model = L"m.wgcm"; + Entry dirE; dirE.action = L"dir"; dirE.rel = L"plugins"; m.e.push_back(dirE); + Entry a; a.action = L"copy"; a.rel = L"plugins\\WrongGPU-RR.asi"; a.inst = Sha256Bytes(rrAsi.data(), rrAsi.size()); a.owner = L"wg"; m.e.push_back(a); + Entry i; i.action = L"copy"; i.rel = L"wronggpu-rr.ini"; i.inst = Sha256Bytes(rrIni.data(), rrIni.size()); i.owner = L"wg"; m.e.push_back(i); + SaveRecord(RecordPath(d), m); + return d; + }; + const wstring d = earlier(L"Unchanged"); + bool threw = false; + try { DoRestore(mc, d, quiet, false, true); } catch (const SetupError&) { threw = true; } + require(!threw && !IsFile(Join(d, L"plugins\\WrongGPU-RR.asi")) && !IsFile(Join(d, L"wronggpu-rr.ini")) && IsFile(Join(d, L"Game.exe")), + "gap 5b: an update's restore removes the earlier install's RR plugin and its settings (the new install then places none)"); + const wstring c = earlier(L"Changed"); + file(Join(c, L"plugins\\WrongGPU-RR.asi"), "another build put here since (synthetic)"); + std::vector w; + threw = false; + try { w = DoRestore(mc, c, quiet, false, true); } catch (const SetupError&) { threw = true; } + bool warned = false; + for (auto& x : w) warned = warned || x == L"Left in place (changed since install): plugins\\WrongGPU-RR.asi"; + require(!threw && IsFile(Join(c, L"plugins\\WrongGPU-RR.asi")) && warned, "gap 5b: an RR plugin changed since the install: left in place, with a warning"); + } // the scan takes managed folders whose record is gone off the list, unless their drive isn't connected wstring offline; const DWORD drives = GetLogicalDrives(); diff --git a/clean/installer/tests/run_coexist_tests.py b/clean/installer/tests/run_coexist_tests.py index 75f8323e..8ff5b0dc 100644 --- a/clean/installer/tests/run_coexist_tests.py +++ b/clean/installer/tests/run_coexist_tests.py @@ -27,6 +27,7 @@ HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import coexist_fixtures as fx # noqa: E402 +import coexist_061_tests as c061 # noqa: E402 import run_installer_tests as suite # noqa: E402 import run_launcher_tests as lt # noqa: E402 from run_installer_tests import diff, read, sha, snapshot, write # noqa: E402 @@ -629,6 +630,7 @@ def main(): test_leftovers_and_orphans(t, opti) test_engine_direct_leftovers(t, opti) test_status_lists_findings(t, opti) + c061.run_all(t, opti, full) drop_entries(t, work) # nothing of this run stays in the test registry (the launcher tests share it) print("\n%d checks passed, %d failed (%.0f s)" % (t.passed, len(t.failures), time.time() - t0)) for f in t.failures: diff --git a/clean/installer/tests/run_installer_tests.py b/clean/installer/tests/run_installer_tests.py index cb933071..5976f828 100644 --- a/clean/installer/tests/run_installer_tests.py +++ b/clean/installer/tests/run_installer_tests.py @@ -1011,10 +1011,11 @@ def test_upgrade_paths(t, payload_dir): GOOD = t.model.file # noqa: N806 t.clear_model() game = {SLOTS[0]: AMD_V1, SLOTS[1]: FSR3, SLOTS[2]: FSR3UP} - # A newer WrongGPU build placed by hand: WrongGPU's version resource, but not the files the install record names. + # A newer WrongGPU build placed by hand: WrongGPU's version resource, but not the files the install record names. Under + # the game's FSR names (the original comes back in their place). 0.6.1: a hand-placed file under another name counts as + # WrongGPU's only by a release's hash (the hand-placed-runtime case below: left in place). hot = {SLOTS[0]: mockpe.make_dll(mockpe.FRONT_END, (0, 5, 0, 0), extra=b"hand-placed front end", exports=mockpe.FFX_API_EXPORTS, dll_name=SLOTS[0]), - SLOTS[2]: mockpe.make_dll(mockpe.FRONT_END, (0, 5, 0, 0), extra=b"hand-placed forwarder", exports=mockpe.FSR3UPSCALER_EXPORTS, dll_name=SLOTS[2]), - "wronggpu_runtime.dll": mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 5, 0, 0), extra=b"hand-placed runtime")} + SLOTS[2]: mockpe.make_dll(mockpe.FRONT_END, (0, 5, 0, 0), extra=b"hand-placed forwarder", exports=mockpe.FSR3UPSCALER_EXPORTS, dll_name=SLOTS[2])} def same(path, data): return os.path.isfile(path) and read(path) == data @@ -1041,7 +1042,7 @@ def tail(rc, log, root=None, want=None): # Defect of 0.4.5-rc: the restore kept the hand-placed DLL, removed the game's renamed original, then refused. root, b, before = installed("hotfix-upgrade", hand_placed=True) rc, log = setup_again(root) - t.check("setup over hand-placed WrongGPU DLLs (front end, a forwarder, the runtime): installed", rc == 0, tail(rc, log)) + t.check("setup over hand-placed WrongGPU DLLs (front end, a forwarder): installed", rc == 0, tail(rc, log)) t.check("...the new payload is in place and the game's three FSR DLLs are kept as *.wronggpu-original.dll", payload_installed(t, b, payload_dir) and kept(b, game), log[-700:]) rec_path = os.path.join(b, "wronggpu-setup", "install.record") rec = read(rec_path).decode() if os.path.isfile(rec_path) else "" @@ -1053,6 +1054,15 @@ def tail(rc, log, root=None, want=None): root, b, before = installed("hotfix-uninstall", hand_placed=True) rc = t.uninstall(b) t.check("uninstall with hand-placed WrongGPU DLLs: the game's originals are back, nothing of WrongGPU left", rc == 0 and snapshot(root) == before, tail(rc, t.logtext(), root, before)) + # 0.6.1: a hand-placed runtime that names WrongGPU but has no release's hash is left in place with a warning + root, b, before = installed("hand-placed-runtime") + hand_runtime = mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 5, 0, 0), extra=b"hand-placed runtime") + write(os.path.join(b, "wronggpu_runtime.dll"), hand_runtime) + rc = t.uninstall(b) + expect = dict(before) + expect[key("bin/x64/wronggpu_runtime.dll")] = sha(hand_runtime) + t.check("uninstall with a hand-placed runtime (WrongGPU's version resource, not a release's hash): left in place, the rest as before", + rc == 0 and snapshot(root) == expect and "changed since install" in t.logtext(), tail(rc, t.logtext(), root, expect)) # The game's original is never removed while WrongGPU's DLL is under the game's name: without a backup, and with a # record that has no entry for WrongGPU's DLL, it comes back from its renamed copy (hash-checked against the record). root, b, before = installed("hotfix-no-backup", hand_placed=True) @@ -1816,8 +1826,7 @@ def tail(rc, log, root=None, want=None): return # A newer WrongGPU build placed by hand over the direct install (the states of test_upgrade_paths). hot = {SLOTS[0]: mockpe.make_dll(mockpe.FRONT_END, (0, 5, 0, 0), extra=b"hand-placed front end", exports=mockpe.FFX_API_EXPORTS, dll_name=SLOTS[0]), - SLOTS[2]: mockpe.make_dll(mockpe.FRONT_END, (0, 5, 0, 0), extra=b"hand-placed forwarder", exports=mockpe.FSR3UPSCALER_EXPORTS, dll_name=SLOTS[2]), - "wronggpu_runtime.dll": mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 5, 0, 0), extra=b"hand-placed runtime")} + SLOTS[2]: mockpe.make_dll(mockpe.FRONT_END, (0, 5, 0, 0), extra=b"hand-placed forwarder", exports=mockpe.FSR3UPSCALER_EXPORTS, dll_name=SLOTS[2])} # (0.6.1: no hand-placed runtime, see hand-placed-runtime) def direct_install(name, version=None, hand_placed=False): root, b = cyberpunk(t, name, model=GOOD) @@ -1863,7 +1872,7 @@ def originals_back(b, expected=None): root, b, before = direct_install("direct-hand-placed-to-hosted", hand_placed=True) rc = t.run(*hosted(root)) log = t.logtext() - t.check("setup over a direct install with hand-placed WrongGPU DLLs (front end, a forwarder, the runtime): the originals are back byte for byte, hosted install", + t.check("setup over a direct install with hand-placed WrongGPU DLLs (front end, a forwarder): the originals are back byte for byte, hosted install", rc == 0 and originals_back(b) and hosted_ok(b), tail(rc, log)) rc = t.uninstall(b) t.check("...and uninstall leaves the game as it was before WrongGPU", rc == 0 and snapshot(root) == before, tail(rc, t.logtext(), root, before)) diff --git a/clean/installer/tests/wg_core_tests.cpp b/clean/installer/tests/wg_core_tests.cpp index 0ed749ac..5fc69b5f 100644 --- a/clean/installer/tests/wg_core_tests.cpp +++ b/clean/installer/tests/wg_core_tests.cpp @@ -12,6 +12,7 @@ #include "wg_core/model.h" #include "wg_core/record.h" #include "wg_core/settings.h" +#include "wg_core/test_temp_guard.h" using namespace wg; @@ -32,7 +33,15 @@ wstring TempFolder() { } // namespace int main() { + if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root try { + // 0.6.1: the test programs' temp-folder guard (test_temp_guard.h): below the root by full path, never by a bare prefix + require(wg_test::UnderRoot(L"Q:\\work\\tmp\\x", L"Q:\\work") && wg_test::UnderRoot(L"q:/work/TMP/", L"Q:\\work\\") && + wg_test::UnderRoot(L"Q:\\work", L"Q:\\work"), "temp guard: a folder below the root (either slash, any case), the root itself"); + require(!wg_test::UnderRoot(L"Q:\\work-x\\tmp", L"Q:\\work") && !wg_test::UnderRoot(L"C:\\Windows\\Temp", L"Q:\\work") && + !wg_test::UnderRoot(L"Q:\\work\\..\\other", L"Q:\\work") && !wg_test::UnderRoot(L"", L"Q:\\work"), + "temp guard: not by a bare prefix, not another drive, not out by .., not an empty path"); + require(wg_test::TempOutsideRoot(L"").empty(), "temp guard: no root configured, no check"); // strings and paths require(Join(L"C:\\a", L"b") == L"C:\\a\\b" && Join(L"C:\\a\\", L"b") == L"C:\\a\\b" && Join(L"", L"b") == L"b", "Join"); require(Parent(L"C:\\a\\b.exe") == L"C:\\a" && BaseName(L"C:\\a\\b.exe") == L"b.exe" && Stem(L"C:\\a\\b.exe") == L"b", "Parent/BaseName/Stem"); diff --git a/clean/installer/tests/wizard_policy_tests.cpp b/clean/installer/tests/wizard_policy_tests.cpp index 407d761a..d8b3627b 100644 --- a/clean/installer/tests/wizard_policy_tests.cpp +++ b/clean/installer/tests/wizard_policy_tests.cpp @@ -1,9 +1,11 @@ // SPDX-License-Identifier: MIT #include "../src/wizard_policy.h" +#include "../src/wg_core/test_temp_guard.h" #include #include int main() { + if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root using namespace wg_wizard; int checks = 0; auto require = [&](bool ok, const char* message) { diff --git a/clean/installer/tools/make_known_releases.py b/clean/installer/tools/make_known_releases.py index a03d9215..f1c9a3aa 100644 --- a/clean/installer/tools/make_known_releases.py +++ b/clean/installer/tools/make_known_releases.py @@ -3,23 +3,30 @@ """Writes src/wg_core/known_releases.h: the SHA-256 and size of every file WrongGPU's releases installed (the launcher recognises leftover WrongGPU files without an install record by these hashes only; build/launcher-design.md section 6). - python make_known_releases.py --out src/wg_core/known_releases.h = ... + python make_known_releases.py --out src/wg_core/known_releases.h [--keep ] = ... -The payload folders are our own release builds (build/release//payload*). Only .dll, .asi and wronggpu-*.txt -files are listed. A hash that two releases share is listed once, with the earlier version. Written for this project; -Python standard library only. +The payload folders are our own release builds (build/release//payload*; 0.6.0: build/release-060-rc/payload and +its RR folder rr). Only .dll, .asi and wronggpu-*.txt files are listed. A hash that two releases share is listed once, with +the earlier version. --keep: the rows of an existing header come first, unchanged (a new release added without rebuilding +the older folders). Written for this project; Python standard library only. """ import argparse import hashlib import os +import re def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", required=True) + ap.add_argument("--keep", help="an existing known_releases.h whose rows are kept first") ap.add_argument("payloads", nargs="+", help="=") a = ap.parse_args() rows, seen = [], set() + if a.keep: + for m in re.finditer(r'\{L"([^"]*)", L"((?:[^"\\]|\\.)*)", (\d+)ull, L"([0-9a-f]{64})"\}', open(a.keep, encoding="utf-8").read()): + rows.append((m.group(1), m.group(2).replace("\\\\", "\\"), int(m.group(3)), m.group(4))) + seen.add(m.group(4)) for item in a.payloads: version, folder = item.split("=", 1) for dirpath, _, files in sorted(os.walk(folder)): From c47d6231e6469cc1a4e348207b21e498c7b409cd Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Fri, 13 Nov 2026 16:02:05 -0500 Subject: [PATCH 2/7] Launcher coexist: review fixes - OptiScaler.ini is the install's while the OptiScaler DLL the record installed is still in place (OptiScaler's menu may point the ini elsewhere), or while its keys point at WrongGPU's files. - A file left in place whose original is in the backup never loses that backup: the uninstall keeps the backup folder; Repair and Update refuse before anything changes, also when a file moved aside is back with other content. An unreadable recorded file stops the uninstall before anything changes. - Other setups' plugins: decided before the earlier install's restore and again after it; only the plugins the player's question listed are moved; plugins an earlier install moved aside go aside again (byte for byte); paths relative to the install folder, RR stays out when the exe folder is outside it. - The switch question defaults to Cancel; Clean up / Adopt of files another mod's setup uses take --confirm-other-setup instead of --force. - The consent check after the restore is gone (checked before anything changes); a game FSR DLL without its original makes the uninstall refuse again ("Nothing was changed"). - Leftovers: WrongGPU's own setup without its record is recognised by its menu plugin's hash, not by file names or the licence text. - Split out for a follow-up: the test builds' temp-folder guard, the RR guard lines in Last run and the library cache's 24th field. - Backups (#70): Update and Repair keep the player's moved-aside OptiScaler.log (the log WrongGPU's OptiScaler wrote there goes, the player's comes back and goes aside again); the move out of a wrong folder refuses like Repair instead of dropping a kept backup. The settings file (#73): wronggpu.ini changed since the install stays through Update and Repair, and the uninstall removes it and says so instead of "left in place". - Comments and test texts describe the behaviour; new tests for these cases and for interrupted operations. Fixes #70 Fixes #73 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/CMakeLists.txt | 28 -- clean/installer/README.md | 25 +- clean/installer/src/app/cli.cpp | 5 +- clean/installer/src/app/launcher_ui.cpp | 8 +- clean/installer/src/app/main.cpp | 6 - clean/installer/src/app/restore_main.cpp | 6 - clean/installer/src/app/ui_game.cpp | 17 +- clean/installer/src/app/ui_library.cpp | 15 +- clean/installer/src/wg_core/coexist.cpp | 48 ++- clean/installer/src/wg_core/coexist.h | 23 +- clean/installer/src/wg_core/detect.cpp | 2 +- clean/installer/src/wg_core/install.cpp | 80 ++-- clean/installer/src/wg_core/install.h | 7 +- clean/installer/src/wg_core/launcher.cpp | 12 +- clean/installer/src/wg_core/launcher.h | 2 + clean/installer/src/wg_core/leftovers.cpp | 14 +- clean/installer/src/wg_core/leftovers.h | 12 +- clean/installer/src/wg_core/logtail.cpp | 42 +- clean/installer/src/wg_core/logtail.h | 24 +- clean/installer/src/wg_core/record.cpp | 88 ++++- clean/installer/src/wg_core/record.h | 13 +- clean/installer/src/wg_core/test_temp_guard.h | 68 ---- clean/installer/tests/coexist_061_tests.py | 371 ++++++++++++++++-- clean/installer/tests/coexist_tests.cpp | 161 +++----- clean/installer/tests/launcher_core_tests.cpp | 133 ++++++- clean/installer/tests/wg_core_tests.cpp | 9 - clean/installer/tests/wizard_policy_tests.cpp | 2 - clean/installer/tools/make_known_releases.py | 3 +- 28 files changed, 773 insertions(+), 451 deletions(-) delete mode 100644 clean/installer/src/wg_core/test_temp_guard.h diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index 2d60bf35..d9c5f402 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -198,34 +198,6 @@ add_test(NAME coexist-core COMMAND coexist-core-tests) if(WRONGGPU_TESTING) add_test(NAME wizard-policy COMMAND wizard-policy-tests) endif() -# 0.6.1: the test programs (and WrongGPU.exe / the restorer of a WRONGGPU_TESTING build) refuse to start when TMP or TEMP is -# outside this folder (src/wg_core/test_temp_guard.h; forward slashes); empty: no check. The temp-guard-* tests start them -# with a temp folder outside it (paths that cannot be created, so a broken guard writes nothing) and pass on the refusal. -set(WRONGGPU_TEST_TEMP_ROOT "" CACHE STRING "Test programs refuse to start when TMP/TEMP is outside this folder (empty: no check)") -if(WRONGGPU_TEST_TEMP_ROOT) - set(WG_GUARDED wg-core-tests launcher-core-tests coexist-core-tests) - if(WRONGGPU_TESTING) - list(APPEND WG_GUARDED wizard-policy-tests WrongGPU WrongGPU-Restore) - endif() - foreach(t IN LISTS WG_GUARDED) - target_compile_definitions(${t} PRIVATE WG_TEST_TEMP_ROOT="${WRONGGPU_TEST_TEMP_ROOT}") - endforeach() - set(WG_OUTSIDE "C:/wg-temp-guard|outside") - foreach(t wg-core-tests launcher-core-tests coexist-core-tests) - add_test(NAME temp-guard-outside-${t} COMMAND ${t}) - set_tests_properties(temp-guard-outside-${t} PROPERTIES ENVIRONMENT "TMP=${WG_OUTSIDE};TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TMP=") - endforeach() - add_test(NAME temp-guard-temp-only COMMAND coexist-core-tests) - set_tests_properties(temp-guard-temp-only PROPERTIES ENVIRONMENT "TMP=${WRONGGPU_TEST_TEMP_ROOT}/tmp/temp-guard-probe;TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TEMP=") - add_test(NAME temp-guard-prefix COMMAND coexist-core-tests) - set_tests_properties(temp-guard-prefix PROPERTIES ENVIRONMENT "TMP=${WRONGGPU_TEST_TEMP_ROOT}-probe|x;TEMP=${WRONGGPU_TEST_TEMP_ROOT}-probe|x" PASS_REGULAR_EXPRESSION "refused: TMP=") - if(WRONGGPU_TESTING) - add_test(NAME temp-guard-outside-wizard-policy-tests COMMAND wizard-policy-tests) - set_tests_properties(temp-guard-outside-wizard-policy-tests PROPERTIES ENVIRONMENT "TMP=${WG_OUTSIDE};TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TMP=") - add_test(NAME temp-guard-outside-launcher COMMAND WrongGPU version) # (a broken guard: the version verb, no window) - set_tests_properties(temp-guard-outside-launcher PROPERTIES ENVIRONMENT "TMP=${WG_OUTSIDE};TEMP=${WG_OUTSIDE}" PASS_REGULAR_EXPRESSION "refused: TMP=") - endif() -endif() target_include_directories(WrongGPU PRIVATE ${GEN}) target_compile_definitions(WrongGPU PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION}) target_link_libraries(WrongGPU PRIVATE wg_ui wg_core wgc_core comctl32 shell32 ole32 oleaut32 uuid advapi32 user32 gdi32 gdiplus dwmapi uxtheme d2d1 d3d11 dxgi dwrite windowscodecs uiautomationcore) diff --git a/clean/installer/README.md b/clean/installer/README.md index ffcf3ba0..2bbda2a3 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -35,7 +35,10 @@ player's OptiScaler.ini back. Tests: `test_asi_plugin`. Other setups' plugins (0.6.1, `ForeignPlugins`): `.asi` files in `plugins\`, `OptiScaler\plugins\` or `wronggpu-plugins\` that the install record doesn't name with that hash. In a Ray Reconstruction game WrongGPU's RR stays out by default (they may hook RR too; the result says so); with the player's OK (the window's question, `--switch-plugins`) they are moved aside -(backed up, put back on uninstall) and WrongGPU's RR goes in. Elsewhere they stay beside WrongGPU's plugin. +(backed up, put back on uninstall) and WrongGPU's RR goes in: exactly the plugins the question listed (`--switch-plugins`: +those there at the time); one that is not listed keeps RR out. Repair and Update keep them aside on that OK (the earlier +install's restore brings them back; byte for byte those go aside again), and RR stays out when the exe folder is outside +the install folder (nothing to move them with). Elsewhere they stay beside WrongGPU's plugin. WrongGPU RR from another package at exactly `plugins\WrongGPU-RR.asi` is overwritten by the install's RR plugin (backed up by its copy entry, put back on uninstall); under any other name it stays. For 007 First Light (`007FirstLight.exe`) the installer also sets OptiScaler's `[Spoofing] DxgiFactoryWrapping=true`: @@ -235,13 +238,19 @@ With the defaults nothing of this section changes the installer. resource (a newer build the player placed by hand), or another payload file whose hash is one of WrongGPU's releases (`known_releases.h`) or of the embedded payload (0.6.1: never by a version resource, which another setup's build may carry; not the settings file). Any other changed FSR DLL follows the rule for game updates above; any other changed - file is left in place with a warning (another setup's OptiScaler over the proxy is named as such). OptiScaler.ini is the - install's only while its keys point at WrongGPU's files; an uninstall that leaves an OptiScaler.ini naming WrongGPU's - files warns that its setup may need them. The game's original of an FSR DLL is never removed while WrongGPU's DLL is - under the game's name: it comes back from the backup, or from its `*.wronggpu-original.dll` copy when the backup - is missing or damaged, checked against the hash in the record. When neither is there (0.6.1), an uninstall leaves - WrongGPU's DLL under the game's name with a warning (verify the game's files in the store) and removes the rest; an - update or repair stops before anything changes, keeping the record and backup. + file is left in place with a warning (another setup's OptiScaler over the proxy is named as such). When such a file + replaced one that was there before WrongGPU (its original is in the backup), that backup is never deleted: an uninstall + keeps the backup folder and says so, an update or repair refuses before anything changes ("Nothing was changed"), as it + does when a file WrongGPU moved aside is back with other content (a log that WrongGPU's own OptiScaler wrote over the + player's moved-aside `OptiScaler.log` is the exception: it is removed and the player's comes back). A recorded file + that cannot be read (another program holds it open) stops the uninstall before anything changes. `wronggpu.ini` + changed since the install (the launcher's settings, or edited by hand) stays through an update or repair, and an + uninstall removes it, as it always does, and says so. OptiScaler.ini is the install's while the OptiScaler DLL + the record installed is still there with its hash (OptiScaler's menu saves the ini with whatever the player picks), or + while its keys still point at WrongGPU's files; an uninstall that leaves an OptiScaler.ini naming WrongGPU's files warns + that its setup may need them. The game's original of an FSR DLL is never removed while WrongGPU's DLL is under the + game's name: it comes back from the backup, or from its `*.wronggpu-original.dll` copy when the backup is missing or + damaged, checked against the hash in the record; when neither is there, the uninstall refuses ("Nothing was changed"). - **Collect logs** (button, `/COLLECT`, or "Modify" in Apps & features): one .zip with WrongGPU's logs and crash notes, the install record, setup log, model source, system information (Windows, GPU, driver, HIP runtime, FSR DLL state, model state, where the output filter comes from, file hashes) and recent Windows crash / GPU-reset events. diff --git a/clean/installer/src/app/cli.cpp b/clean/installer/src/app/cli.cpp index f1e80d20..9529333a 100644 --- a/clean/installer/src/app/cli.cpp +++ b/clean/installer/src/app/cli.cpp @@ -9,7 +9,8 @@ // --removeold: remove an older WrongGPU install first, --force: no GPU/HIP block, // --rr-config-fix=on|off: Borderlands 4 / Hogwarts Legacy's Engine.ini question answered) // uninstall | rollback | adopt (adopt --all: every 0.5.x install the scan finds) -// clean-leftovers | adopt-leftovers WrongGPU files without a record (hash-matched to our releases only) +// clean-leftovers | adopt-leftovers WrongGPU files without a record (hash-matched to our releases only); +// --confirm-other-setup: also when another mod's setup uses them (refused without it) // set key=value ... per-game settings (written to the game at once); set --global key=value ... // set opti.
.=value: an editable key of the game's OptiScaler.ini // get [key] | get --global @@ -603,7 +604,7 @@ int Verb(const wstring& verb, const Args& a, Output& o) { if (!Game(a, o, exe, dir)) return o.code; if (NeedsElevation(dir)) { o.j.S("error", L"administrator permission is needed for " + dir); return EXIT_REFUSED; } OpRequest r; ParseOp(verb, r.op); r.exe = exe; r.dir = dir; - r.force = a.has(L"force"); // 0.6.1: files another mod's setup uses are left alone unless --force + r.otherSetupOk = a.has(L"confirm-other-setup"); // 0.6.1: files another mod's setup uses are left alone unless confirmed OpLogBegin(); Ui ui; ui.step = [](int, int, const wstring&) {}; ui.log = [](const wstring& s) { LogLine(g.ctx, s); }; const OpResult res = RunOp(g.ctx, r, ui); diff --git a/clean/installer/src/app/launcher_ui.cpp b/clean/installer/src/app/launcher_ui.cpp index bed3b484..1a40b64b 100644 --- a/clean/installer/src/app/launcher_ui.cpp +++ b/clean/installer/src/app/launcher_ui.cpp @@ -804,8 +804,9 @@ bool PrepareOp(const GameEntry& e, Op op, OpRequest& r, bool* failed, bool* gone r.experimental = true; if (t.conflicts.modsFound()) { wstring list; for (auto& m : t.conflicts.mods) list += (list.empty() ? L"" : L", ") + m; - if (!Confirm(L"Switch to WrongGPU's OptiScaler setup?\n\nThis game already has " + list + L". Your files are backed up and put back exactly as they were if you uninstall WrongGPU.", - 0, L"Switch", L"Cancel")) + // (0.6.1: Cancel is the default: the files may be another setup's OptiScaler over WrongGPU's own) + if (RunDialog(0, L"Switch to WrongGPU's OptiScaler setup?\n\nThis game already has " + list + L". Your files are backed up and put back exactly as they were if you uninstall WrongGPU.", + {{L"Switch", 1, false, false}, {L"Cancel", 0, true, false}}, 0) != 1) return false; r.moveMods = true; } @@ -815,6 +816,7 @@ bool PrepareOp(const GameEntry& e, Op op, OpRequest& r, bool* failed, bool* gone L"Ray Reconstruction as WrongGPU's does, so WrongGPU's Ray Reconstruction goes in only if they are moved aside. They are backed " L"up and put back when you uninstall WrongGPU. If you keep them, WrongGPU installs without its Ray Reconstruction.", {{L"Move them aside", 1, false, false}, {L"Keep them", 0, true, false}}, 0) == 1; + if (r.movePlugins) r.movePluginsList = t.coexist.foreignPlugins; // exactly the plugins the question listed } if (t.conflicts.oldFound()) { if (!Confirm(L"Remove the older WrongGPU install first?\n\nAn older WrongGPU (DLSS 4.5 AMD) install is in this game. The game's original files are put back exactly as they were.", 0, @@ -872,7 +874,7 @@ void OnLeftovers(const GameEntry& e, bool clean) { Inform(L"Details\n\n" + names, 2); } OpRequest r; r.op = clean ? Op::CleanLeftovers : Op::AdoptLeftovers; r.exe = e.exe; r.dir = e.dir; - r.force = e.leftoversOtherSetup; // (0.6.1: the player chose "anyway" for another mod's setup's files) + r.otherSetupOk = e.leftoversOtherSetup; // (0.6.1: the player chose "anyway" for another mod's setup's files) StartOp(r); } // An install the launcher does not manage yet (WrongGPU setup 0.5, no profile.ini, its own uninstall entry): adopted, diff --git a/clean/installer/src/app/main.cpp b/clean/installer/src/app/main.cpp index f231690c..4790b72e 100644 --- a/clean/installer/src/app/main.cpp +++ b/clean/installer/src/app/main.cpp @@ -95,9 +95,6 @@ using std::wstring; #include "wg_core/payload.h" #include "wg_core/record.h" #include "wg_core/rrprep.h" -#ifdef WRONGGPU_TESTING -#include "wg_core/test_temp_guard.h" -#endif namespace wg::app { @@ -205,9 +202,6 @@ using namespace wg; using namespace wg::app; int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, PWSTR, int) { -#ifdef WRONGGPU_TESTING - if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // test builds: never a temp folder outside the configured root -#endif { // release 0.6.0: the Ray Reconstruction helper (rrprep.h): this program copied under a game's program name, started by // the launcher with --rr-prepare ; nothing else of the launcher runs in it int hc = 0; LPWSTR* hv = CommandLineToArgvW(GetCommandLineW(), &hc); diff --git a/clean/installer/src/app/restore_main.cpp b/clean/installer/src/app/restore_main.cpp index 1e488d18..047b856d 100644 --- a/clean/installer/src/app/restore_main.cpp +++ b/clean/installer/src/app/restore_main.cpp @@ -18,9 +18,6 @@ #include "wg_core/launcher.h" #include "wg_core/logs.h" #include "wg_core/record.h" -#ifdef WRONGGPU_TESTING -#include "wg_core/test_temp_guard.h" -#endif #ifndef WRONGGPU_VERSION_STR #define WRONGGPU_VERSION_STR L"0.0.0" @@ -69,9 +66,6 @@ wstring PlainError(const SetupError& e) { } // namespace int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int) { -#ifdef WRONGGPU_TESTING - if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // test builds: never a temp folder outside the configured root -#endif SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32); static const EmbeddedData data{nullptr, 0, 0, L"", 0, L"", 0, WRONGGPU_VERSION_STR}; Context ctx; diff --git a/clean/installer/src/app/ui_game.cpp b/clean/installer/src/app/ui_game.cpp index 97eb0591..159a58a0 100644 --- a/clean/installer/src/app/ui_game.cpp +++ b/clean/installer/src/app/ui_game.cpp @@ -47,7 +47,7 @@ static bool RrNoEdition(const GameEntry& e) { return e.rrDirect && e.hasRecord & // WrongGPU's Ray Reconstruction takes RR in this game: its files are in, it is on, the RR data is ready, and this build can // run it there bool RrOn(const GameEntry& e) { return e.rrInstalled && e.rrEnabled && v.rrReady && !RrBlocked(e) && !RrNoEdition(e); } -bool RrAloneLastRun(const GameEntry& e) { return RrOn(e) && e.last.RrAlone(); } // (0.6.1: never a run whose guard kept WrongGPU RR off) +bool RrAloneLastRun(const GameEntry& e) { return RrOn(e) && e.last.found && (e.last.rrOnly || e.last.rrUpscaled); } static bool RrFailedRun(const LastRun& lr); // (the Last run section, r7 #2) wstring RrModeName(const wstring& mode) { return mode == L"exact" ? L"Exact" : mode == L"fast" ? L"Fast" : L"Accurate"; } @@ -461,7 +461,7 @@ FindingWords WordsOf(const Finding& f) { w.sub = f.decision == Decision::Warn ? L"It may hook Ray Reconstruction too, so WrongGPU's Ray Reconstruction stays out unless you move them aside when you install." : L"It stays. WrongGPU's plugin goes beside it."; break; - case Tool::WrongGPU: // 0.6.1 (gap 4): WrongGPU's RR plugin placed by another package (it exports WrongGPU RR's marker) + case Tool::WrongGPU: // 0.6.1: WrongGPU's RR plugin placed by another package (it exports WrongGPU RR's marker) if (f.what == L"WrongGPU RR (from another package)") w.sub = L"It stays. WrongGPU never moves its own Ray Reconstruction plugin aside."; break; case Tool::Cet: case Tool::Red4ext: case Tool::Ue4ss: w.sub = L"It stays. WrongGPU doesn't touch it."; break; @@ -1840,8 +1840,6 @@ static wstring RunWarning(const wstring& kind, const wstring& text, bool footSay if (kind == L"foreign-vtable") return L"An overlay or another mod (ReShade, Special K) took over some frames, so they used AMD FSR."; if (kind == L"xess-no-depth") return L"With XeSS chosen in the game, Model M gets less from the game and may look worse. Choose DLSS or FSR in the game's settings."; if (kind == L"no-depth") return L"The game gives the upscaler less than it needs, so Model M may look worse."; - // 0.6.1: the RR plugin's guard line itself (another Ray Reconstruction plugin, a second copy of WrongGPU RR, hooks replaced) - if (kind == L"rr-guard") return L"Ray Reconstruction: " + text + L"."; (void)text; // a kind this launcher does not know: the core's own sentence stays behind Show, with the log's lines return L"WrongGPU noted a warning in this run. Select Show to read it."; } @@ -1893,14 +1891,6 @@ static float LastRunSection(Gfx& gx, float x, float y, float w) { auto times = [](const wstring& s) { wstring o; for (wchar_t ch : s) o += ch == L'x' ? wstring(L"\u202f\u00d7\u202f") : wstring(1, ch); return o; }; // the run known from the RR log alone (r4 #1: Borderlands 4, Hogwarts Legacy and RE Requiem run Ray Reconstruction only, and // the front end logs nothing there): the Denoiser row leads, with its mode and cost, then the size; no upscaler rows - if (lr.rrGuardOff) { // 0.6.1: a session whose guard kept WrongGPU RR off: its line says why - KvOpt dn; - dn.sub = RunWarning(L"rr-guard", lr.rrGuard, false); - yy += KvRow(gx, x, yy, w, true, L"Denoiser", L"WrongGPU RR stayed off", dn); - yy += ActRow(gx, x, yy, w, false, false, ID_G_LOG, L"Open log", ic::external, Rec()); - yy += CollectRow(gx, x, yy, w); - return yy - top; - } if (lr.rrOnly) { KvOpt dn; wstring m = lr.rrMode.empty() ? wstring() : RrModeName(lr.rrMode); @@ -1953,8 +1943,7 @@ static float LastRunSection(Gfx& gx, float x, float y, float w) { // the RR data gone since that run: the page's Ray Reconstruction line says so, and this says it too if (!v.rrReady) m += (m.empty() ? L"" : L"\n") + wstring(L"Its data is missing now, so the next run uses the game's own denoiser."); dn.sub = m; - } else if (!lr.rrGuard.empty()) dn.sub = L"WrongGPU RR stayed off in this run (its reason is below)."; // 0.6.1: the RR plugin's guard - else if (lr.rrFound) dn.sub = L"The game didn't ask for it in this run."; // the RR plugin ran, the game never made an instance + } else if (lr.rrFound) dn.sub = L"The game didn't ask for it in this run."; // the RR plugin ran, the game never made an instance yy += KvRow(gx, x, yy, w, false, L"Denoiser", lr.rrUsed ? L"Ray Reconstruction" : L"Not used", dn); } if (!lr.renderSize.empty() && !lr.outputSize.empty()) yy += KvRow(gx, x, yy, w, false, L"Size", times(lr.renderSize) + L" \u2192 " + times(lr.outputSize)); diff --git a/clean/installer/src/app/ui_library.cpp b/clean/installer/src/app/ui_library.cpp index 4c00e15d..3699f349 100644 --- a/clean/installer/src/app/ui_library.cpp +++ b/clean/installer/src/app/ui_library.cpp @@ -308,7 +308,6 @@ static wstring LockupStatus(const GameEntry& e) { t += L" Last run " + When(e.last.when) + L": " + noRrFrame; else if (e.last.found && e.last.ready) t += L" Last run " + When(e.last.when) + on + (rrFailed ? L"; " + noRrFrame : wstring(L".")); else if (e.last.found && e.last.upscaler == L"amd") t += L" Last run " + When(e.last.when) + L" with AMD FSR" + (rrFailed ? L"; " + noRrFrame : wstring(L".")); - else if (e.last.found && e.last.rrGuardOff) t += L" Last run " + When(e.last.when) + L": WrongGPU RR stayed off."; // 0.6.1: its guard (the page says why) else if (!e.last.found) t += L" Not played yet."; // the lockup's own words return t; } @@ -1261,7 +1260,7 @@ static float FeatureBanner(Gfx& gx, float x0, float y, float cw, float h, int in // Clean up: their entries are not read yet, BusyWhy says so); Play and the games' pages work. A game that was running // is listed as it was before it ran. static const wchar_t kListHead[] = L"wronggpu-library-list 2"; // 2: the flags carry rrDirect and optiEdition (a list of 1 is not read) -constexpr size_t kListFields = 24; // (0.6.1: the last run's guard line; a list of 23 fields, before it, is read too) +constexpr size_t kListFields = 23; static wstring ListPath() { return gl.paths.dataDir.empty() ? wstring() : Join(gl.paths.dataDir, L"library-list.txt"); } void SaveLibrarySnapshot() { @@ -1280,10 +1279,11 @@ void SaveLibrarySnapshot() { const wstring flags = {bit(e.hasRecord), bit(e.recordV1), bit(e.perGameEntry), bit(e.hosted), bit(e.adoptable), bit(e.repairSuggested), bit(e.exeFound), bit(e.hasPrevious), bit(e.rrUses), bit(e.rrInstalled), bit(e.rrEnabled), bit(e.rrPathTracingOnly), bit(e.needsFound), bit(e.rrDirect), bit(e.optiEdition)}; - const wstring lastFlags = LastRunCacheFlags(e.last); // (r4 #1, r6 #1; 0.6.1: rrGuardOff, and its line in the last field) + const wstring lastFlags = {bit(e.last.found), bit(e.last.ready), bit(e.last.optiPlugin), bit(e.last.upscaled), bit(e.last.rrOnly), + bit(e.last.rrUpscaled)}; // (r4 #1, r6 #1) const wstring f[kListFields] = {e.name, e.exe, e.dir, e.source, e.appid, std::to_wstring((int)e.status), e.statusText, e.installedVersion, flags, e.previous, e.proxy, e.rrWhy, e.rrMode, e.needs, e.needsWhy, e.needsPage, e.needsGame, problems, - e.last.when, e.last.upscaler, e.last.executor, e.last.process, lastFlags, e.last.rrGuard}; + e.last.when, e.last.upscaler, e.last.executor, e.last.process, lastFlags}; for (size_t k = 0; k < kListFields; ++k) out += (k ? L"\t" : L"") + (k == 17 ? f[k] : field(f[k])); out += L"\n"; } @@ -1312,7 +1312,7 @@ bool LoadLibrarySnapshot() { std::vector games; for (size_t i = 1; i < lines.size() && games.size() < (size_t)kTileSpan; ++i) { const std::vector f = split(lines[i], L'\t'); - if ((f.size() != kListFields && f.size() != kListFields - 1) || f[0].empty() || f[8].size() != 15) continue; + if (f.size() != kListFields || f[0].empty() || f[8].size() != 15 || (f[22].size() != 3 && f[22].size() != 5 && f[22].size() != 6)) continue; // (3: before r4; 5: before r6) GameEntry e; e.name = f[0]; e.exe = f[1]; e.dir = f[2]; e.source = f[3]; e.appid = f[4]; const int st = _wtoi(f[5].c_str()); @@ -1328,8 +1328,9 @@ bool LoadLibrarySnapshot() { e.needs = f[13]; e.needsWhy = f[14]; e.needsPage = f[15]; e.needsGame = f[16]; if (!f[17].empty()) e.problems = split(f[17], (wchar_t)0x1f); e.last.when = f[18]; e.last.upscaler = f[19]; e.last.executor = f[20]; e.last.process = f[21]; - if (!ReadLastRunCacheFlags(f[22], e.last)) continue; // (3, 5, 6 or 7 flags: logtail.h) - if (f.size() == kListFields) e.last.rrGuard = f[23]; // 0.6.1: the RR plugin's guard line (the page's Last run and the banner from the start) + e.last.found = f[22][0] == L'1'; e.last.ready = f[22][1] == L'1'; e.last.optiPlugin = f[22][2] == L'1'; + if (f[22].size() >= 5) { e.last.upscaled = f[22][3] == L'1'; e.last.rrOnly = f[22][4] == L'1'; } + if (f[22].size() >= 6) e.last.rrUpscaled = f[22][5] == L'1'; if (e.status == GameStatus::Running) { // not running any more, most likely: as it was before it ran e.status = !e.hasRecord ? GameStatus::Eligible : !e.problems.empty() ? GameStatus::NeedsRepair : GameStatus::Installed; e.statusText.clear(); diff --git a/clean/installer/src/wg_core/coexist.cpp b/clean/installer/src/wg_core/coexist.cpp index b29ad3a4..f310d561 100644 --- a/clean/installer/src/wg_core/coexist.cpp +++ b/clean/installer/src/wg_core/coexist.cpp @@ -5,6 +5,7 @@ #include +#include #include #include "checks.h" // FindAntiCheat, VersionLess @@ -193,22 +194,53 @@ bool ExportsRrContract(const wstring& path) { MappedFile f(path, 256ull << 20); // the file's bytes only: never loaded as a module return f.data && ReadPeExports(f.data, f.size).count(kRrContractExport) > 0; } +// exeDir relative to dir ("" when the same folder); false when exeDir is not dir or a folder below it +static bool RelativeTo(const wstring& dir, const wstring& exeDir, wstring& rel) { + const wstring d = FullPath(dir), x = FullPath(exeDir); + rel.clear(); + if (IEq(d, x)) return true; + const wstring base = !d.empty() && d.back() == L'\\' ? d : d + L"\\"; + if (x.size() <= base.size() || !StartsWithI(x, base)) return false; + rel = x.substr(base.size()); + return true; +} // The .asi files of OptiScaler's plugin folders that the install record does not name with that hash; withMarker: those that -// export WrongGPU RR's marker (true) or the others (false) -static std::vector UnrecordedPlugins(const wstring& exeDir, const Record* ours, bool withMarker) { +// export WrongGPU RR's marker (true) or the others (false). The record's paths are relative to recordDir (empty: exeDir) +static std::vector UnrecordedPlugins(const wstring& exeDir, const Record* ours, bool withMarker, const wstring& recordDir = L"") { std::vector out; + wstring prefix; + if (ours && !recordDir.empty() && !RelativeTo(recordDir, exeDir, prefix)) ours = nullptr; // (it cannot name them) for (auto sub : kPluginDirs) for (auto& f : ListFiles(Join(exeDir, sub), L"*.asi")) { - const wstring rel = f.substr(exeDir.size() + 1); + const wstring rel = f.substr(exeDir.size() + 1), recRel = prefix.empty() ? rel : Join(prefix, rel); bool mine = false; if (ours) for (auto& e : ours->e) - if (e.action == L"copy" && IEq(e.rel, rel) && !e.inst.empty()) { mine = IEq(Sha256File(f), e.inst); break; } + if (e.action == L"copy" && IEq(e.rel, recRel) && !e.inst.empty()) { mine = IEq(Sha256File(f), e.inst); break; } if (!mine && ExportsRrContract(f) == withMarker) out.push_back(rel); } return out; } -std::vector ForeignPlugins(const wstring& exeDir, const Record* ours) { return UnrecordedPlugins(exeDir, ours, false); } +std::vector ForeignPlugins(const wstring& exeDir, const Record* ours, const wstring& recordDir) { + return UnrecordedPlugins(exeDir, ours, false, recordDir); +} +PluginPlan PlanPluginsAside(const wstring& exeDir, const wstring& dir, const std::vector& plugins, const std::vector& agreed, + const std::map& movedBefore) { + PluginPlan p; + wstring prefix; + const bool inside = RelativeTo(dir, exeDir, prefix); + for (auto& f : plugins) { + const wstring rel = prefix.empty() ? f : Join(prefix, f); + bool ok = std::any_of(agreed.begin(), agreed.end(), [&](const wstring& a) { return IEq(a, f); }); + if (!ok && inside) { + const auto it = movedBefore.find(Lower(rel)); + ok = it != movedBefore.end() && IEq(Sha256File(Join(exeDir, f)), it->second); + } + if (ok && inside) p.moveAside.push_back(rel); + else { p.blocking.push_back(f); p.outside = p.outside || !inside; } + } + return p; +} std::vector OurPluginsFromOtherPackages(const wstring& exeDir, const Record* ours) { return UnrecordedPlugins(exeDir, ours, true); } wstring ForeignPluginsText(const std::vector& plugins) { return L"Other OptiScaler plugins are in this game (" + JoinList(plugins) + L"). They may hook Ray Reconstruction as WrongGPU's RR plugin does, so " @@ -230,7 +262,7 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& auto isOurs = [&](const wstring& rel) { if (!sameDir) return false; if (hostedOurs && IEq(rel, L"OptiScaler.log")) return true; - if (hostedOurs && IEq(rel, L"OptiScaler.ini")) return OptiIniIsOurs(dir, *ours); // 0.6.1: while its keys point at WrongGPU's files + if (hostedOurs && IEq(rel, L"OptiScaler.ini")) return OptiIniIsOurs(dir, *ours); // 0.6.1: beside WrongGPU's OptiScaler, or pointing at WrongGPU's files auto it = ourHash.find(Lower(rel)); if (it == ourHash.end()) return false; if (EndsWithI(rel, L".ini") || EndsWithI(rel, L".log")) return true; // settings and logs of our install @@ -359,8 +391,8 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring& // 0.6.1: other setups' plugins in OptiScaler's plugin folders: in a Ray Reconstruction game WrongGPU's RR stays out unless // the player moves them aside (they may hook RR too); elsewhere they stay beside WrongGPU's plugin - // (gap 5a: the plugin folders are the exe folder's; when the install folder is another one, the record that names their - // files is the exe folder's own, if there is one: an earlier install there is not "another setup") + // (the plugin folders are the exe folder's; when the install folder is another one, the record that names their files is + // the exe folder's own, if there is one: an earlier install there is not "another setup") Record exeDirRecord; const Record* pluginRecord = sameDir ? ours : LoadRecord(RecordPath(exeDir), exeDirRecord) && !exeDirRecord.legacy ? &exeDirRecord : nullptr; if (const auto kit = OurPluginsFromOtherPackages(exeDir, pluginRecord); !kit.empty()) diff --git a/clean/installer/src/wg_core/coexist.h b/clean/installer/src/wg_core/coexist.h index 5f11a989..5577e2a9 100644 --- a/clean/installer/src/wg_core/coexist.h +++ b/clean/installer/src/wg_core/coexist.h @@ -80,12 +80,25 @@ inline const wchar_t* const kPluginDirs[] = {L"plugins", L"OptiScaler\\plugins", // The .asi files in those folders next to the exe that are not WrongGPU's install's own (the record copied them there with // that hash), relative to exeDir. Another setup's plugin may hook Ray Reconstruction as WrongGPU's RR plugin does: by default // WrongGPU's RR stays out of such a game (with a warning); with the player's OK (Consent::movePlugins) they are moved aside -// (backed up, put back on uninstall) and WrongGPU's RR goes in. Never by a plugin's name alone. -std::vector ForeignPlugins(const wstring& exeDir, const Record* ours); -// 0.6.1 (gap 4): WrongGPU's RR plugin exports this marker (clean/rr_f/proxy/include/wg_rr_settings_contract.h, +// (backed up, put back on uninstall) and WrongGPU's RR goes in. Never by a plugin's name alone. recordDir: the folder the +// record's paths are relative to (the install folder; empty: exeDir); a record of a folder that exeDir is not in names none. +std::vector ForeignPlugins(const wstring& exeDir, const Record* ours, const wstring& recordDir = L""); +// 0.6.1: what an install does with those plugins (exeDir-relative, from ForeignPlugins) in a Ray Reconstruction game. Each +// one the player agreed to move (`agreed`, as the question listed them) or that an earlier install moved aside with the +// player's OK (`movedBefore`: its record's disable entries, lower-case path relative to dir -> the hash moved; byte for byte +// that file) goes into moveAside, as a path relative to the install folder dir. Any other one is in `blocking`: WrongGPU's RR +// stays out. When exeDir is not dir or a folder below it nothing can be moved: every plugin is blocking (outside: true). +struct PluginPlan { + std::vector moveAside; // relative to dir + std::vector blocking; // relative to exeDir + bool outside = false; // a blocking plugin is outside the install folder +}; +PluginPlan PlanPluginsAside(const wstring& exeDir, const wstring& dir, const std::vector& plugins, const std::vector& agreed, + const std::map& movedBefore); +// 0.6.1: WrongGPU's RR plugin exports this marker (clean/rr_f/proxy/include/wg_rr_settings_contract.h, // WG_RR_CONTRACT_EXPORT). A plugin file that exports it is WrongGPU's own RR plugin whatever its name or hash (a copy another -// package placed from the integration kit): never "another setup's plugin", never moved aside. Read from the file's PE -// export table, never by loading it. +// package placed): never "another setup's plugin", never moved aside. Read from the file's PE export table, never by +// loading it. const char* const kRrContractExport = "WrongGPU_GetSettingsContract"; bool ExportsRrContract(const wstring& path); // Those copies in OptiScaler's plugin folders that the install record doesn't name with that hash (relative to exeDir): the diff --git a/clean/installer/src/wg_core/detect.cpp b/clean/installer/src/wg_core/detect.cpp index 6828fbd1..7e3f3e34 100644 --- a/clean/installer/src/wg_core/detect.cpp +++ b/clean/installer/src/wg_core/detect.cpp @@ -495,7 +495,7 @@ GameTarget InspectGame(Context& ctx, const wstring& exe, const wstring& displayN auto isOurs = [&](const wstring& f) { const auto it = ours.find(Lower(f)); if (it == ours.end()) return false; - if (IEq(f, L"OptiScaler.ini")) return OptiIniIsOurs(t.dir, t.record); // (fix 4: its keys still point at WrongGPU's files) + if (IEq(f, L"OptiScaler.ini")) return OptiIniIsOurs(t.dir, t.record); // (beside WrongGPU's OptiScaler, or pointing at WrongGPU's files) if (EndsWithI(f, L".ini") || EndsWithI(f, L".log")) return true; return !it->second.empty() && IEq(Sha256File(Join(t.dir, f)), it->second); }; diff --git a/clean/installer/src/wg_core/install.cpp b/clean/installer/src/wg_core/install.cpp index 61b6c583..12798a1a 100644 --- a/clean/installer/src/wg_core/install.cpp +++ b/clean/installer/src/wg_core/install.cpp @@ -181,14 +181,33 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod // Ray Reconstruction (rr.h): a game that uses it gets this build's RR files too (OptiScaler setup only: the RR plugin is // one of OptiScaler's plugins) const bool rrGame = (!kDirectRoute || ctx.opti.ok()) && RrPayloadAvailable(ctx) && DetectRr(target.exe).uses; - // 0.6.1: another setup's plugins in OptiScaler's plugin folders may hook RR too: WrongGPU's RR stays out unless the player - // chose to move them aside (then backed up as moved, below); the earlier install's own plugins are not "another setup's" - const std::vector foreignAsi = rrGame ? ForeignPlugins(target.exeDir, target.installed ? &target.record : nullptr) : std::vector{}; - const bool rr = rrGame && (foreignAsi.empty() || consent.movePlugins); - if (rrGame && !rr) { - const wstring w = ForeignPluginsText(foreignAsi); + // 0.6.1: other setups' plugins in OptiScaler's plugin folders may hook RR too: WrongGPU's RR goes in only when every one of + // them is moved aside (backed up as moved, below): those the player agreed to move (the plugins the question listed; + // --switch-plugins: those in the folder now), and those the earlier install moved aside with that OK (its record's + // disable entries, byte for byte: they come back with its restore and go aside again). Any other one keeps WrongGPU's RR + // out, as does one outside the install folder (nothing to move it with). Decided here, before anything changes, against + // what the folder holds now (the plugins moved before are still in the backup; one put back by hand since is asked + // about like any other); checked again after the earlier install's restore (below). The earlier install's own plugins + // are not "another setup's". + std::map pluginsMovedBefore; // lower-case path relative to dir -> the hash the player's OK was for + if (target.installed) + for (auto& e : target.record.e) + if (e.action == L"disable" && !e.orig.empty() && EndsWithI(e.rel, L".asi")) pluginsMovedBefore[Lower(e.rel)] = e.orig; + const std::vector pluginsNow = rrGame ? ForeignPlugins(target.exeDir, target.installed ? &target.record : nullptr, dir) : std::vector{}; + const std::vector pluginsOk = !consent.movePlugins ? std::vector{} : consent.plugins.empty() ? pluginsNow : consent.plugins; + auto pluginsKeepRrOut = [&](const PluginPlan& p) { + wstring list; + for (auto& f : p.blocking) list += (list.empty() ? L"" : L", ") + f; + const wstring w = p.outside ? L"Other OptiScaler plugins are in this game (" + list + L") outside the folder WrongGPU installs to, so they " + L"can't be moved aside: WrongGPU's Ray Reconstruction was left out (they may hook Ray Reconstruction as WrongGPU's RR plugin does)." + : ForeignPluginsText(p.blocking); LogLine(ctx, L"Ray Reconstruction: " + w); warnings.push_back(w); + }; + bool rr = rrGame; + if (rr) { + const PluginPlan before = PlanPluginsAside(target.exeDir, dir, pluginsNow, pluginsOk, {}); + if (!before.blocking.empty()) { rr = false; pluginsKeepRrOut(before); } } if (rr) for (size_t i = 0; i < ctx.data->rrCount; ++i) { @@ -214,6 +233,8 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod } } if (!model.ok()) Fail(model.error.empty() ? L"No usable DLSS model file." : model.error, model.damaged ? EXIT_DAMAGED : EXIT_NO_MODEL); + // (the player's OK for other mods' files, before anything changes: target.conflicts is the folder as the earlier install's + // restore leaves it, apart from the files that restore brings back, which are those the player's OK was for) if (target.conflicts.modsFound() && !consent.moveMods) Fail(L"Other upscaler mods were found. They have to be moved aside first (with a backup).", EXIT_OTHER_MODS); if (target.conflicts.oldFound() && !consent.removeOld) Fail(L"An older WrongGPU (DLSS 4.5 AMD) install was found. It has to be removed first.", EXIT_OLD_INSTALL); if (DWORD e = WriteTest(dir)) Fail(L"Cannot write to the game folder: " + ErrText(e)); @@ -470,6 +491,14 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod } LogLine(ctx, L"OptiScaler mode: OptiScaler " + ctx.opti.version + L" as " + proxy + L", WrongGPU as " + (slot ? kOptiSlotFrontEnd : kOptiFrontEnd) + L", " + std::to_wstring(optiFiles.size()) + L" OptiScaler files"); } + // 0.6.1: the other setups' plugins as the restore left the folder (the ones the earlier install moved aside are back): + // each goes aside again only with the OK it had (the player's, or byte for byte the earlier install's move); any other + // one keeps WrongGPU's RR out after all (nothing is moved without that OK) + PluginPlan pluginsAside; + if (rr) { + pluginsAside = PlanPluginsAside(target.exeDir, dir, ForeignPlugins(target.exeDir, nullptr), pluginsOk, pluginsMovedBefore); + if (!pluginsAside.blocking.empty()) { rr = false; pluginsKeepRrOut(pluginsAside); pluginsAside = PluginPlan(); } + } if (rr) { // the RR plugin beside WrongGPU's plugin (OptiScaler's plugins folder, or the plugin's own next to Ultimate ASI // Loader), the RR runtime next to the exe, wronggpu-rr.ini (the RR data) and the plugin's settings file: from a @@ -510,26 +539,11 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod const Conflicts now = FindConflicts(dir, target.exeDir); if (!now.outside.empty() || !now.legacyRecordDir.empty()) Fail(L"Files of another mod or an older install could not be handled automatically: " + (now.outside.empty() ? now.legacyRecordDir : now.outside[0]), EXIT_OTHER_MODS); - // 0.6.1: the player's OK is checked against what is in the folder now, after the restore: another setup's OptiScaler that - // replaced WrongGPU's proxy stays through the restore and is never moved aside without the switch question's answer. The - // files the earlier install moved aside or replaced with the player's OK (its record's disable entries, and copies over a - // file that was there, backed up) come back through the restore: byte for byte those, they go aside again on that OK; - // anything else needs it anew - if (now.modsFound() && !consent.moveMods) { - std::map movedBefore; // lower-case name -> the hash the player's OK was for - if (target.installed) - for (auto& e : target.record.e) - if ((e.action == L"disable" || (e.action == L"copy" && e.existed)) && !e.orig.empty()) movedBefore[Lower(e.rel)] = e.orig; - wstring list; - for (auto& f : now.modFiles) { - const auto it = movedBefore.find(Lower(f)); - if (it != movedBefore.end() && IEq(Sha256File(Join(dir, f)), it->second)) continue; - list += (list.empty() ? L"" : L", ") + f; - } - if (!list.empty()) - Fail(L"This game has its own OptiScaler or another upscaler mod (" + list + L"). Switch to WrongGPU's OptiScaler setup? " - L"Your files are backed up and put back byte for byte when WrongGPU is uninstalled.", EXIT_OTHER_MODS); - } + // (0.6.1: other mods' files after the restore need no question here: the player's OK was checked before anything changed, + // at the top, against target.conflicts. The restore leaves in place only files that were there then (another setup's + // OptiScaler over WrongGPU's proxy is among them, so it was asked about), and what it brings back is byte for byte what + // the earlier install moved aside or replaced with the player's OK (its disable entries, its copies over a file that + // was there): those go aside again below on that OK.) Record m; m.version = ctx.data->version; m.game = dir; m.exe = target.exe; m.status = target.validated ? L"validated" : L"experimental"; m.regkey = ctx.perGameEntry ? RegKeyFor(dir) : L""; m.model = ModelFile(ctx); m.modelM = modelM.outcome; LogLine(ctx, L"target " + target.exe + L" | install folder " + dir + L" | status " + m.status); @@ -591,12 +605,12 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod if (!IsAmdFidelityFxName(f) && std::find_if(optiFiles.begin(), optiFiles.end(), [&](const OptiFile& o) { return IEq(o.rel, f); }) == optiFiles.end()) disable.push_back(f); for (auto& f : now.legacyFiles) disable.push_back(f); - // other setups' plugins, moved aside with the player's OK so WrongGPU's RR plugin is the only one (fix 2); one at a path - // this install writes is backed up by its copy entry instead - if (rr && consent.movePlugins) - for (auto& f : ForeignPlugins(target.exeDir, nullptr)) { - const wstring rel = IEq(FullPath(target.exeDir), FullPath(dir)) ? f : wstring(); - if (rel.empty() || std::find_if(optiFiles.begin(), optiFiles.end(), [&](const OptiFile& o) { return IEq(o.rel, rel); }) != optiFiles.end()) continue; + // other setups' plugins, moved aside with the player's OK so WrongGPU's RR plugin is the only one (exactly those the plan + // above found: the ones the player agreed to, and the ones the earlier install had moved aside; paths relative to the + // install folder); one at a path this install writes is backed up by its copy entry instead + if (rr) + for (auto& rel : pluginsAside.moveAside) { + if (std::find_if(optiFiles.begin(), optiFiles.end(), [&](const OptiFile& o) { return IEq(o.rel, rel); }) != optiFiles.end()) continue; bool written = false; for (auto& pf : *ctx.data) written = written || (payloadUsed(pf) && IEq(payloadRel(pf), rel)); if (written || std::find_if(disable.begin(), disable.end(), [&](const wstring& d) { return IEq(d, rel); }) != disable.end()) continue; @@ -615,7 +629,7 @@ std::vector DoInstall(Context& ctx, const GameTarget& target, const Mod for (auto& w : warnings) if (w == k->second) w = L"Moved aside with your OK: " + name + L" (another setup's file that had replaced WrongGPU's; kept in the backup and put back when WrongGPU is uninstalled)."; } - // another setup's file the restore left in place (fix 4: its OptiScaler.ini) that this install now replaces with the + // another setup's file the restore left in place (its OptiScaler.ini, beside its OptiScaler) that this install now replaces with the // switch question's OK: backed up (an entry that existed) and said as that for (auto& e : m.e) { const auto k = e.action == L"copy" && e.existed ? keptByRestore.find(Lower(e.rel)) : keptByRestore.end(); diff --git a/clean/installer/src/wg_core/install.h b/clean/installer/src/wg_core/install.h index e2baee30..0cc119a5 100644 --- a/clean/installer/src/wg_core/install.h +++ b/clean/installer/src/wg_core/install.h @@ -9,7 +9,12 @@ namespace wg { struct CompareDll { wstring path, version, game; std::vector v; }; -struct Consent { bool moveMods = false, removeOld = false, movePlugins = false; }; // movePlugins (0.6.1): other setups' plugins aside (ForeignPlugins) +// movePlugins (0.6.1): other setups' plugins aside (ForeignPlugins): those in `plugins` (paths relative to the exe folder, as +// the player's question listed them), or every one there when it is empty (--switch-plugins) +struct Consent { + bool moveMods = false, removeOld = false, movePlugins = false; + std::vector plugins; +}; void RemoveEarlierDirect(Context& ctx, const GameTarget& target, Ui& ui, std::vector& warnings); wstring CompareRecordFile(); diff --git a/clean/installer/src/wg_core/launcher.cpp b/clean/installer/src/wg_core/launcher.cpp index b6032cac..6cabf1a7 100644 --- a/clean/installer/src/wg_core/launcher.cpp +++ b/clean/installer/src/wg_core/launcher.cpp @@ -401,7 +401,7 @@ GameEntry EntryFor(Context& ctx, const wstring& exeIn, const wstring& name, cons else if (const Finding* no = t.coexist.refusal()) { g.status = GameStatus::Refused; g.statusText = L"Refused: " + no->what; } else if (!g.needs.empty() && !g.needsFound) { g.status = GameStatus::NeedsPrereq; g.statusText = L"Needs " + g.needs + L": " + g.needsGame + L" blocks OptiScaler without it"; } else if (t.conflicts.oldFound()) { g.status = GameStatus::OldInstall; g.statusText = L"Has an older WrongGPU (DLSS 4.5 AMD): Install removes it first"; } - else if (!(g.leftovers = FindLeftovers(ctx, g.dir)).empty() && !(g.leftoversOtherSetup = LeftoversUsedByOtherSetup(g.dir, g.leftovers))) { + else if (!(g.leftovers = FindLeftovers(ctx, g.dir)).empty() && !(g.leftoversOtherSetup = LeftoversUsedByOtherSetup(ctx, g.dir, g.leftovers))) { g.status = GameStatus::Leftovers; g.statusText = L"Leftover WrongGPU files without a record: " + LeftoverSummary(g.leftovers) + L" - Clean up or Adopt"; } @@ -979,7 +979,7 @@ static void InstallOp(Context& ctx, const OpRequest& r, Ui& ui, OpResult& res) { // leftover WrongGPU files without a record: cleaned up first only with the player's OK (never automatic) std::vector leftovers = target.installed ? std::vector{} : FindLeftovers(ctx, dir); // 0.6.1: beside another mod's OptiScaler they are that setup's: never removed first; the install backs up any it replaces - if (LeftoversUsedByOtherSetup(dir, leftovers)) { + if (LeftoversUsedByOtherSetup(ctx, dir, leftovers)) { res.notes.push_back(L"WrongGPU files " + wstring(kLeftoversOtherSetup) + L" were left alone: " + LeftoverSummary(leftovers) + L" (any the install replaces is backed up and put back when WrongGPU is uninstalled)"); LogLine(ctx, res.notes.back()); @@ -1042,7 +1042,7 @@ static void InstallOp(Context& ctx, const OpRequest& r, Ui& ui, OpResult& res) { const RrConfigFix keepFix = target.installed ? target.record.rrconfig : !wrongDir.empty() ? wrong.rrconfig : RrConfigFix(); string keepBackup = wrongDir.empty() ? string() : wrongFixBackup; if (keepFix.backup && wrongDir.empty()) ReadAll(RrConfigBackupPath(dir), keepBackup); - Consent consent; consent.moveMods = r.moveMods; consent.removeOld = r.removeOld; consent.movePlugins = r.movePlugins; + Consent consent; consent.moveMods = r.moveMods; consent.removeOld = r.removeOld; consent.movePlugins = r.movePlugins; consent.plugins = r.movePluginsList; try { for (auto& w : DoInstall(ctx, target, model, consent, ui, sys.hip)) res.warnings.push_back(w); } catch (const SetupError&) { @@ -1123,7 +1123,7 @@ OpResult RunOp(Context& ctx, const OpRequest& r, Ui& ui) { const std::vector lo = FindLeftovers(ctx, r.dir); if (lo.empty()) Fail(L"There are no leftover WrongGPU files (without an install record) in " + r.dir + L".", EXIT_NOT_INSTALLED); if (!r.exe.empty() && GameRunning(r.exe)) Fail(BaseName(r.exe) + L" is running. Close it first.", EXIT_REFUSED); - if (!r.force && LeftoversUsedByOtherSetup(r.dir, lo)) // 0.6.1: left alone unless the player confirms (force) + if (!r.otherSetupOk && LeftoversUsedByOtherSetup(ctx, r.dir, lo)) // 0.6.1: left alone unless the player confirms (--confirm-other-setup) Fail(L"These WrongGPU files are " + wstring(kLeftoversOtherSetup) + L", so they are left alone: removing or adopting them can break that mod. " L"Confirm to " + (r.op == Op::CleanLeftovers ? L"remove" : L"adopt") + L" them anyway.", EXIT_REFUSED); if (r.op == Op::CleanLeftovers) { @@ -1165,6 +1165,8 @@ string JobText(const OpRequest& r, const wstring& localAppData, const wstring& l for (size_t i = 0; i < kSettingCount; ++i) t += string("profile.") + kSettings[i].key + "=" + r.profile.get(kSettings[i].key) + "\r\n"; for (auto& e : r.optiEdits) t += "optikey." + e.first + "=" + e.second + "\r\n"; if (r.movePlugins) t += "moveplugins=1\r\n"; + for (size_t i = 0; i < r.movePluginsList.size(); ++i) t += "moveplugin." + std::to_string(i) + "=" + ToUtf8(r.movePluginsList[i]) + "\r\n"; + if (r.otherSetupOk) t += "othersetupok=1\r\n"; if (r.optiReset) t += "optireset=1\r\n"; if (r.optiKeep) t += "optikeep=1\r\n"; if (r.optiOnly) t += "optionly=1\r\n"; @@ -1196,6 +1198,8 @@ bool ParseJob(const string& text, OpRequest& r, wstring& localAppData, wstring& else if (k == "force") r.force = Truthy(kv.second); else if (k == "noscan") r.noScan = Truthy(kv.second); else if (k == "moveplugins") r.movePlugins = Truthy(kv.second); + else if (k.rfind("moveplugin.", 0) == 0) r.movePluginsList.push_back(v); + else if (k == "othersetupok") r.otherSetupOk = Truthy(kv.second); else if (k == "optireset") r.optiReset = Truthy(kv.second); else if (k == "optikeep") r.optiKeep = Truthy(kv.second); else if (k == "optionly") r.optiOnly = Truthy(kv.second); diff --git a/clean/installer/src/wg_core/launcher.h b/clean/installer/src/wg_core/launcher.h index b015067a..ac2efdfc 100644 --- a/clean/installer/src/wg_core/launcher.h +++ b/clean/installer/src/wg_core/launcher.h @@ -175,6 +175,8 @@ struct OpRequest { wstring modelDll; // a DLSS model file to try first bool moveMods = false, removeOld = false, experimental = false, force = false, noScan = true; bool movePlugins = false; // 0.6.1: other setups' OptiScaler plugins moved aside with the player's OK (WrongGPU's RR then goes in) + std::vector movePluginsList; // ...exactly these (relative to the exe folder, as the question listed them); empty: every one there + bool otherSetupOk = false; // 0.6.1: Clean up / Adopt of WrongGPU files another mod's setup uses, confirmed (--confirm-other-setup) bool hasProfile = false; // apply: this profile (else the game's profile.ini); install: the profile a new install starts with Profile profile; // apply, the OptiScaler tab: edits of editable keys ("Section.Key", value); reset: the editable keys back to what the diff --git a/clean/installer/src/wg_core/leftovers.cpp b/clean/installer/src/wg_core/leftovers.cpp index 7f65a8e5..dbb40fa2 100644 --- a/clean/installer/src/wg_core/leftovers.cpp +++ b/clean/installer/src/wg_core/leftovers.cpp @@ -130,12 +130,16 @@ std::vector FindLeftovers(Context& ctx, const wstring& dir) { return out; } -bool LeftoversUsedByOtherSetup(const wstring& dir, const std::vector& files) { +bool LeftoversUsedByOtherSetup(Context& ctx, const wstring& dir, const std::vector& files) { if (files.empty() || dir.empty() || IsFile(RecordPath(dir)) || !FindConflicts(dir, dir).modsFound()) return false; - // WrongGPU's own setup that lost its record: a file only the launcher installs is among them (the menu plugin, or the - // licence under its payload name); the integration kit ships neither under these names - for (auto& f : files) - if (IEq(f.rel, kAsiPlugin) || IEq(f.rel, Join(kAsiPluginOwnDir, BaseName(kAsiPlugin))) || IEq(f.rel, L"wronggpu-license.txt")) return false; + // WrongGPU's own OptiScaler setup that lost its record: WrongGPU's menu plugin is among them, by its hash (a build of + // WrongGPU.asi from a release or this program's payload), wherever it is. Never by a file's name, and never by the + // licence text (any package that ships WrongGPU's files carries it) + const KnownSet k = KnownFiles(ctx); + for (auto& f : files) { + const auto it = k.byHash.find(Lower(f.sha)); + if (it != k.byHash.end() && IEq(BaseName(it->second.name), BaseName(kAsiPlugin))) return false; + } return true; } diff --git a/clean/installer/src/wg_core/leftovers.h b/clean/installer/src/wg_core/leftovers.h index 0fc87cb3..b3cad09e 100644 --- a/clean/installer/src/wg_core/leftovers.h +++ b/clean/installer/src/wg_core/leftovers.h @@ -24,12 +24,12 @@ struct Leftover { wstring rel, sha, version, abs; }; std::vector FindLeftovers(Context& ctx, const wstring& dir); wstring LeftoverSummary(const std::vector& files); // "3 files of WrongGPU 0.4.5 (wronggpu_runtime.dll, ...)" // 0.6.1: an OptiScaler that WrongGPU didn't install is next to them (its marker files, or a DLL a game loads by name whose -// fingerprint is OptiScaler; there is no install record): another mod's setup that uses WrongGPU's files (its integration -// kit). They are "used by another mod's setup" and left alone by default: no Leftovers status, Clean up and Adopt only when -// confirmed, an install backs up any it replaces (put back on uninstall) instead of removing them first. Not when `files` -// hold one only WrongGPU's launcher installs (plugins\WrongGPU.asi, wronggpu-license.txt; the integration kit ships neither -// under those names): that is WrongGPU's own OptiScaler setup that lost its record, and the OptiScaler is its own. -bool LeftoversUsedByOtherSetup(const wstring& dir, const std::vector& files); +// fingerprint is OptiScaler; there is no install record): another mod's setup that uses WrongGPU's files. They are "used by +// another mod's setup" and left alone by default: no Leftovers status, Clean up and Adopt only when confirmed, an install +// backs up any it replaces (put back on uninstall) instead of removing them first. Not when `files` hold WrongGPU's menu +// plugin, by its hash (a build of WrongGPU.asi from a release or the embedded payload): that is WrongGPU's own OptiScaler +// setup that lost its record, and the OptiScaler is its own. Never by a file's name, never by the licence text. +bool LeftoversUsedByOtherSetup(Context& ctx, const wstring& dir, const std::vector& files); const wchar_t* const kLeftoversOtherSetup = L"used by another mod's setup (an OptiScaler that WrongGPU didn't install is next to them)"; // Clean up: each file's hash is checked again right before it is removed; anything else stays. A FidelityFX DLL of ours // in an engine plugin folder is removed only when the game's own DLL (kept as .wronggpu-original.dll) is there to diff --git a/clean/installer/src/wg_core/logtail.cpp b/clean/installer/src/wg_core/logtail.cpp index baab2ddf..6135fd76 100644 --- a/clean/installer/src/wg_core/logtail.cpp +++ b/clean/installer/src/wg_core/logtail.cpp @@ -2,8 +2,6 @@ // WrongGPU launcher core: "Last run" from wronggpu-fsr.log (logtail.h). Written for this project. #include "logtail.h" -#include - #include "gamerules.h" #include "optiscaler.h" @@ -205,8 +203,7 @@ wstring LastRun::Summary() const { else if (upscaler == L"network" && !created) s = L"WrongGPU not used (the game asked for no upscaler)"; else if (upscaler == L"network") s = L"Model M did not start"; else s = L"started" + (upscaler.empty() ? wstring() : L" (" + upscaler + L")"); - if (rrGuardOff && upscaler.empty()) s = L"Ray Reconstruction: WrongGPU RR stayed off"; // 0.6.1: its guard (Last run says why) - else if ((rrOnly && upscaler.empty()) || rrUpscaled) // a Ray Reconstruction session alone (r4 #1), or RR upscaling where Model M didn't (r6 #1) + if ((rrOnly && upscaler.empty()) || rrUpscaled) // a Ray Reconstruction session alone (r4 #1), or RR upscaling where Model M didn't (r6 #1) s = rrFrames <= 0 ? wstring(L"Ray Reconstruction: no successful frame") // an attempt without one (r6 #2) : L"Ray Reconstruction" + (rrMs.empty() ? wstring() : L" (" + rrMs + L" ms a frame)"); if (!support.empty()) s += L" \u00b7 " + support; @@ -243,8 +240,7 @@ void ParseRrLog(const string& text, LastRun& r) { // a long session: its "attached" line has scrolled out of the log's tail (ReadTail keeps 256 KB) while its instance // and timing lines are still there; with no other load line in the tail, the whole tail is that session if (text.find("load: process ") != string::npos || - (text.find("runtime: create instance") == string::npos && text.find(" ms per frame") == string::npos && - std::none_of(std::begin(kRrGuardLines), std::end(kRrGuardLines), [&](const char* g) { return text.find(g) != string::npos; }))) + (text.find("runtime: create instance") == string::npos && text.find(" ms per frame") == string::npos)) return; start = 0; } @@ -285,14 +281,6 @@ void ParseRrLog(const string& text, LastRun& r) { r.rrNote = L"the game's request was refused (" + why(b.substr(nr + kRefused.size())) + L")"; } if (b.find("colour passed through, success reported") != string::npos) r.rrPassThrough = true; - // 0.6.1: the plugin's coexistence guard (another RR plugin, a second copy of WrongGPU RR, hooks replaced): its line from - // the sentence on (the last one; its whole text up to 400 characters: the lines run to about 250) - for (const char* g : kRrGuardLines) - if (const size_t gp = b.find(g); gp != string::npos) { - const string line = b.substr(gp); - r.rrGuard = FromUtf8(line.size() > 400 ? line.substr(0, 397) + "..." : line); - break; - } // the mode: an Exact the plugin refused runs Accurate; a switch "rr_mode accurate -> fast"; "rr_mode=fast", "rr_mode fast" if (b.find("using accurate") != string::npos || b.find("accurate runs") != string::npos) r.rrMode = L"accurate"; else if (const size_t arrow = b.find(" -> "); arrow != string::npos && b.find("rr_mode ") != string::npos && b.find("rr_mode ") < arrow) { @@ -388,8 +376,7 @@ bool CountRrRun(LastRun& r) { // Requiem) run Ray Reconstruction only, and the front end writes no log there. An attempt counts whether or not a frame // succeeded (r6 #2: a failed one is a run that says so, never "Not played yet" or an older run's success); "upscaled" is RR // frames evaluated successfully (r5 #1) - // 0.6.1: a session whose guard kept WrongGPU RR off (rrGuard) is a run too: Last run says why - if (!r.rrFound || (!r.rrUsed && r.rrGuard.empty())) return false; + if (!r.rrFound || !r.rrUsed) return false; // the same game session in the front end's log too (r5 #3): its own evidence stays as it is (created: the game asked for // Model M; upscaled: Model M upscaled a frame), so the page never says Model M worked, or failed, on RR's frames; RR's // frames show on the Denoiser row. Where Model M upscaled none, RR did the upscaling (it denoises and upscales in one pass, @@ -401,27 +388,11 @@ bool CountRrRun(LastRun& r) { return true; } r.rrOnly = true; - r.found = true; - r.created = r.rrUsed; // (a guard session alone: the game's request never reached WrongGPU RR) - r.rrGuardOff = !r.rrUsed && !r.rrGuard.empty(); + r.found = r.created = true; r.upscaled = r.rrFrames > 0; return true; } -wstring LastRunCacheFlags(const LastRun& r) { - auto bit = [](bool b) { return b ? L'1' : L'0'; }; - return {bit(r.found), bit(r.ready), bit(r.optiPlugin), bit(r.upscaled), bit(r.rrOnly), bit(r.rrUpscaled), bit(r.rrGuardOff)}; -} -bool ReadLastRunCacheFlags(const wstring& f, LastRun& r) { - if (f.size() != 3 && f.size() != 5 && f.size() != 6 && f.size() != 7) return false; // (3: before r4; 5: before r6; 6: before 0.6.1) - for (wchar_t c : f) if (c != L'0' && c != L'1') return false; - r.found = f[0] == L'1'; r.ready = f[1] == L'1'; r.optiPlugin = f[2] == L'1'; - if (f.size() >= 5) { r.upscaled = f[3] == L'1'; r.rrOnly = f[4] == L'1'; } - if (f.size() >= 6) r.rrUpscaled = f[5] == L'1'; - if (f.size() >= 7) r.rrGuardOff = f[6] == L'1'; - return true; -} - wstring RrLogPath(const wstring& installDir) { const wstring here = Join(installDir, L"wronggpu-rr.log"), mirrored = Join(Join(installDir, kMirrorDir), L"wronggpu-rr.log"); WIN32_FILE_ATTRIBUTE_DATA a{}, b{}; @@ -460,8 +431,7 @@ RrJoin JoinRrSession(const SessionSpan& front, const SessionSpan& rr) { // The RR session's evidence into the run (the same game session, or the RR session alone) static void TakeRr(LastRun& r, const LastRun& rr) { r.rrFound = rr.rrFound; r.rrUsed = rr.rrUsed; r.rrMode = rr.rrMode; r.rrMs = rr.rrMs; r.rrFrames = rr.rrFrames; r.rrClock = rr.rrClock; - r.rrNote = rr.rrNote; r.rrPassThrough = rr.rrPassThrough; r.rrGuard = rr.rrGuard; - if (!rr.rrGuard.empty()) r.warnings.push_back({L"rr-guard", rr.rrGuard}); // 0.6.1: the RR plugin's guard line, shown in Last run + r.rrNote = rr.rrNote; r.rrPassThrough = rr.rrPassThrough; if (r.renderSize.empty() && r.outputSize.empty()) { r.renderSize = rr.renderSize; r.outputSize = rr.outputSize; } // (an RR-only run's sizes) } @@ -488,7 +458,7 @@ LastRun ReadLastRun(const wstring& installDir) { if (rr.rrFound) { const RrJoin join = !have || !r.found ? RrJoin::RrNewer : JoinRrSession(SpanOf(r.clock, wt), SpanOf(rr.rrClock, rwt)); if (join == RrJoin::Same || (join == RrJoin::RrNewer && !(have && r.found))) TakeRr(r, rr); - else if (join == RrJoin::RrNewer && (rr.rrUsed || !rr.rrGuard.empty())) { r = LastRun(); TakeRr(r, rr); have = false; } + else if (join == RrJoin::RrNewer && rr.rrUsed) { r = LastRun(); TakeRr(r, rr); have = false; } } r.plugin = asi.plugin; for (auto& w : asi.warnings) r.warnings.push_back(w); diff --git a/clean/installer/src/wg_core/logtail.h b/clean/installer/src/wg_core/logtail.h index f96605d6..02f997f5 100644 --- a/clean/installer/src/wg_core/logtail.h +++ b/clean/installer/src/wg_core/logtail.h @@ -32,7 +32,7 @@ struct LastRun { wstring support; // the last [support] WG-... code wstring renderSize, outputSize; // the last "WrongGPU frame:" line's R=WxH and O=WxH (the window's stat tiles) wstring plugin; // WrongGPU.asi: "hooked", "not-hooked" (wronggpu-asi.log), empty without its log - struct Warning { wstring kind, text; }; // kind: foreign-vtable, no-depth, xess-no-depth, plugin-not-hooked, rr-guard + struct Warning { wstring kind, text; }; // kind: foreign-vtable, no-depth, xess-no-depth, plugin-not-hooked std::vector warnings; // Ray Reconstruction (wronggpu-rr.log, the RR plugin's log next to the exe; its last session) bool rrFound = false; // the RR plugin's log has a session @@ -49,13 +49,6 @@ struct LastRun { wstring rrNote; // the RR log's last failure reason (r6 #2): the runtime's "evaluate failed before any pass: " or // "create: failed ()", or the direct route's "RR feature refused (...): " (r7 #3); empty without one bool rrPassThrough = false; // the plugin passed the game's colour through for a failed evaluate ("colour passed through") - // 0.6.1: the RR plugin's coexistence guard line in that session (kRrGuardLines; clean/rr_f/proxy/HOOK-MODE.md, "Another Ray - // Reconstruction plugin"), from its sentence on: WrongGPU RR stayed off, or was replaced, in that run. The last one; empty - // without one. Last run shows it (warning kind "rr-guard"); an RR-only session with one is a run that says so - wstring rrGuard; - // ...and the run is that RR-only session alone, where the guard kept WrongGPU RR off (no RR request reached it; CountRrRun): - // no Ray Reconstruction in it, whatever the RR setup. Kept in the game list's startup cache (LastRunCacheFlags) - bool rrGuardOff = false; // A session of the RR plugin where the game asked for RR counts as a run (r4 #1: Borderlands 4, Hogwarts Legacy and RE Requiem // run Ray Reconstruction only, so the front end writes no log there; r6 #2: an attempt counts whether or not a frame succeeded): // without a front-end session ReadLastRun sets found and created for it, and upscaled only with frames evaluated ("upscaled" for @@ -77,15 +70,7 @@ struct LastRun { // WrongGPU upscaled frames in the run: Model M's own frames (upscaled; for an RR-only run its RR frames), or Ray Reconstruction's // in one session with the front end where Model M upscaled none (rrUpscaled, r6 #1). The checklist and the header's Worked test bool AnyUpscaled() const { return found && (upscaled || rrUpscaled); } - // Ray Reconstruction alone in the run (r4 #1, r6 #1): an RR-only run, or RR upscaling where Model M didn't; never a run whose - // guard kept WrongGPU RR off (0.6.1) - bool RrAlone() const { return found && ((rrOnly && !rrGuardOff) || rrUpscaled); } }; -// 0.6.1: the last run in the game list's startup cache (library-list.txt, ui_library.cpp): its flags as 0 / 1 characters (found, -// ready, optiPlugin, upscaled, rrOnly, rrUpscaled, rrGuardOff) and, in a field of its own, the guard line (rrGuard). Read back: -// 3, 5, 6 or 7 characters (lists of earlier builds); false for anything else. -wstring LastRunCacheFlags(const LastRun& r); -bool ReadLastRunCacheFlags(const wstring& flags, LastRun& r); // A log's last session on the PC's local clock (seconds): its process id, its start and its end. From the times of day the log // has, on the day of the file's last write (the day before when the last one is later than the write: a copied log). @@ -121,13 +106,6 @@ void ParseAsiLog(const string& text, LastRun& r); // a switch in OptiScaler's menu or in the runtime), the last timing line's GPU time a frame. A session whose "attached" line has // scrolled out of the tail (no other load line in it, but its instance or timing lines): the whole tail. void ParseRrLog(const string& text, LastRun& r); -// 0.6.1: the beginnings of the RR plugin's guard lines where WrongGPU RR stays off (clean/rr_f/proxy/HOOK-MODE.md at -// the RR guard, "Log lines"; each right after the log's time stamp), matched in a line of its session. Never -// the take mode's "another Ray Reconstruction plugin is active; rr_other_plugin=take: WrongGPU RR goes in front of it (": -// WrongGPU RR is on there. -inline const char* const kRrGuardLines[] = {"another Ray Reconstruction plugin is active; WrongGPU RR stays off (", - "a second copy of WrongGPU RR is loaded (", - "a plugin loaded after WrongGPU replaced its hooks; rr_other_plugin=take cannot be applied"}; // OptiScaler.log names XeSS as the game's upscaler input (only used to name the cause of a "no depth" warning). bool OptiLogMentionsXess(const string& text); // Reads the last 256 KB of \wronggpu-fsr.log, the plugin's log (next to OptiScaler or in its own folder), the RR diff --git a/clean/installer/src/wg_core/record.cpp b/clean/installer/src/wg_core/record.cpp index 0746aa74..e93a8bab 100644 --- a/clean/installer/src/wg_core/record.cpp +++ b/clean/installer/src/wg_core/record.cpp @@ -195,6 +195,14 @@ bool HostedRecord(const Record& m) { for (auto& e : m.e) if (e.action == L"copy" bool OptiIniIsOurs(const wstring& dir, const Record& m) { string text, v; if (!ReadAll(Join(dir, L"OptiScaler.ini"), text)) return false; + // OptiScaler's menu saves the ini with whatever the player picks there (the upscaler too): while the OptiScaler DLL the + // record installed is in place with that hash, the ini beside it is the install's + if (!m.proxy.empty()) + for (auto& e : m.e) + if (e.action == L"copy" && IEq(e.rel, m.proxy) && !e.inst.empty()) { + if (IsFile(Target(dir, e.rel)) && IEq(Sha256File(Target(dir, e.rel)), e.inst)) return true; + break; + } auto trimmed = [](string s) { const char* const ws = " \t\r\n\""; const size_t a = s.find_first_not_of(ws), z = s.find_last_not_of(ws); @@ -398,6 +406,20 @@ void StartCleanup(Context& ctx, const wstring& state, const wstring& self, const } } +// A log the OptiScaler of WrongGPU's setup writes next to itself while the game runs (as RemoveRuntimeFiles removes them): +// over a player's log that the install moved aside, it is the install's own, never "another file there now" +static bool OptiRuntimeLog(const Record& m, const wstring& rel) { + if (!HostedRecord(m) || rel.find(L'\\') != wstring::npos) return false; + return IEq(rel, L"OptiScaler.log") || IEq(rel, L"fakenvapi.log") || (StartsWithI(rel, L"OptiScaler.previous") && EndsWithI(rel, L".log")); +} + +// An update or repair that would lose the backup of a file that was there before WrongGPU (another file is in its place now) +static wstring KeptBackupRefusal(const wstring& rel) { + return L"Nothing was changed: " + rel + L" is not the file WrongGPU installed or moved aside (another file is there now), and the backup holds the " + + rel + L" that was there before WrongGPU. A repair or update would replace that backup. Uninstall WrongGPU instead (it keeps the backup " + L"folder), or move the other " + rel + L" away first."; +} + std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool failedInstall, bool keepState, std::map* keptWarnings) { Record m; if (!LoadRecord(RecordPath(dir), m) || m.legacy) Fail(L"No WrongGPU installation record was found in " + dir + L".", EXIT_NOT_INSTALLED); @@ -423,17 +445,7 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa if (!Exists(b) || Sha256File(b) != e.orig) { // The game's FSR DLL is in the folder a second time, next to WrongGPU's: that copy will do. const wstring kept = sl ? Target(dir, sl->original) : wstring(); - const bool keptOk = !kept.empty() && Sha256File(kept) == e.orig; - // 0.6.1: an uninstall never takes a game FSR DLL away without the game's original to put back (neither - // the backup nor the kept copy): the file under the game's name stays, with a warning, and the rest of - // the install goes. An update or repair still stops here (record and backup stay for the next try). - if (!keptOk && sl && !keepState) { - skip.insert(i); - warnings.push_back(L"Left in place: " + e.rel + L" (WrongGPU's file under the game's name: the game's own " + e.rel + - L" isn't in the backup to put back). Verify the game's files in your store to get it back."); - continue; - } - if (!keptOk) Fail(L"The backup of " + e.rel + L" is missing or damaged. Nothing was changed."); + if (kept.empty() || Sha256File(kept) != e.orig) Fail(L"The backup of " + e.rel + L" is missing or damaged. Nothing was changed."); from[i] = kept; } } @@ -441,16 +453,37 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa wstring t = Target(dir, e.rel); if (Exists(t)) { wstring h = Sha256File(t), info; + // 0.6.1: a file that cannot be read (another program holds it open without sharing, such as the game) is + // never taken for "changed since the install" and left behind: the restore stops before anything changes + if (h.empty()) Fail(L"Cannot read " + e.rel + L": another program may have it open (the game?). Close it and try again. Nothing was changed.", EXIT_REFUSED); if (h != e.inst && h != e.orig) { // the RR plugin's settings files: it rewrites them itself (its keys, the mode chosen in OptiScaler's - // menu); they are WrongGPU's all the same and go with the install - if (e.action == L"copy" && !e.existed && IsRrSettingsFile(e.rel)) { - ui.log(e.rel + L" was rewritten by WrongGPU's Ray Reconstruction plugin: removed with the rest"); + // menu); they are WrongGPU's all the same and go with the install (0.6.1: also over a file that was + // there, an earlier install's: that one comes back from the backup) + if (e.action == L"copy" && IsRrSettingsFile(e.rel)) { + ui.log(e.rel + L" was rewritten by WrongGPU's Ray Reconstruction plugin: " + + wstring(e.existed ? L"the file that was there before is put back" : L"removed with the rest")); + continue; + } + // 0.6.1: WrongGPU's settings file (wronggpu.ini beside the front end): the launcher's settings and the + // player's edits change it; it is the install's all the same. An update or repair keeps it in place + // for the new install, which carries its settings over; an uninstall removes it, as it always does + // (RemoveRuntimeFiles; a file that was there before comes back from the backup first and goes with + // it), and says so (never "left in place") + if (e.action == L"copy" && IEq(e.rel, L"wronggpu.ini")) { + if (keepState) { + skip.insert(i); + ui.log(L"wronggpu.ini was changed since the install (WrongGPU's settings): kept for the new install"); + } else { + warnings.push_back(L"wronggpu.ini had changed since the install (WrongGPU's settings, edited by hand or by the launcher): " + L"removed with the rest, as an uninstall does."); + } continue; } // rc6 L5: the OptiScaler.ini of this install's OptiScaler setup, saved by OptiScaler's own menu: the // install's all the same (removed with it; a player's file it replaced comes back from the backup). - // 0.6.1: only while its keys still point at WrongGPU's files (OptiIniIsOurs); else it is another + // 0.6.1: only while WrongGPU's OptiScaler DLL is still there or its keys point at WrongGPU's files + // (OptiIniIsOurs); else it is another // setup's: left in place with a warning (an update replaces it only with the switch question's OK, // and then backs it up) if (e.action == L"copy" && IEq(e.rel, L"OptiScaler.ini") && OptiIniIsOurs(dir, m)) { @@ -468,18 +501,33 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa ui.log(e.rel + L" is not the file that was installed, but it is WrongGPU's own" + (sl ? L" (" + info + L")" : wstring(L" (a release's file)")) + L": removed with the rest"); continue; } + // 0.6.1: the file that was there before the install is in the backup (e.existed; a game FSR DLL the + // game itself replaced is the exception: its new file is the game's): a restore that leaves this file + // in place never deletes that backup. An uninstall keeps the backup folder (said at the end); an update + // or repair would replace it with the new install's backup, so it stops here, before anything changes + if (e.existed && !IsSlotName(e.rel)) { + if (keepState) Fail(KeptBackupRefusal(e.rel), EXIT_REFUSED); + keepBackup = true; + warnings.push_back(L"The " + e.rel + L" that was there before WrongGPU stays in the backup: " + BackupPath(dir, e.rel)); + } skip.insert(i); // 0.6.1: another tool's file there now (another setup's OptiScaler over WrongGPU's proxy) is named as such const Fingerprint fp = e.action == L"copy" && !IsSlotName(e.rel) ? IdentifyFile(t) : Fingerprint(); warnings.push_back(e.action == L"copy" && IsSlotName(e.rel) ? L"The game replaced " + e.rel + L" (probably an update); its new file was kept." : e.action == L"copy" && IEq(e.rel, L"OptiScaler.ini") - ? L"Left in place: OptiScaler.ini no longer points at WrongGPU's files (another setup changed it), so it was not removed." + ? L"Left in place: OptiScaler.ini no longer points at WrongGPU's files and WrongGPU's OptiScaler DLL was replaced (another setup's), so it was not removed." : fp.tool == Tool::OptiScaler ? L"Left in place: " + e.rel + L" is now another setup's OptiScaler (not the file WrongGPU installed)." : L"Left in place (changed since install): " + e.rel); if (keptWarnings) (*keptWarnings)[Lower(e.rel)] = warnings.back(); } } } + // 0.6.1: a file the install moved aside that is back with other content: its original stays in the backup (the + // restore below keeps the backup folder on an uninstall); an update or repair would replace that backup with + // the new install's, so it stops here, before anything changes + // (a log WrongGPU's OptiScaler wrote there is the install's: it goes and the player's comes back, OptiRuntimeLog) + if (keepState && e.action == L"disable" && !OptiRuntimeLog(m, e.rel) && Exists(Target(dir, e.rel)) && Sha256File(Target(dir, e.rel)) != e.orig) + Fail(KeptBackupRefusal(e.rel), EXIT_REFUSED); } } for (size_t k = m.e.size(); k-- > 0;) { // reverse order of installation @@ -511,7 +559,13 @@ std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool fa } else if (Exists(t)) { ForceDelete(t); ui.log(L"removed " + e.rel); } } else { // disable: put the original file back if (!Exists(b)) { if (failedInstall) continue; Fail(L"Backup of " + e.rel + L" is missing."); } - if (Exists(t)) { + if (Exists(t) && Sha256File(t) != e.orig && OptiRuntimeLog(m, e.rel)) { + // 0.6.1: the log WrongGPU's OptiScaler wrote over the player's moved-aside one: removed, the player's comes back + ForceDelete(t); + CopyChecked(b, t); + if (Sha256File(t) != e.orig) Fail(L"Restore verification failed for " + e.rel); + ui.log(L"restored " + e.rel + L" (the log WrongGPU's OptiScaler wrote there was removed)"); + } else if (Exists(t)) { if (Sha256File(t) != e.orig) { keepBackup = true; warnings.push_back(e.rel + L" exists again with different content; the original stays in the backup folder."); } } else { CopyChecked(b, t); ui.log(L"restored " + e.rel); } } diff --git a/clean/installer/src/wg_core/record.h b/clean/installer/src/wg_core/record.h index 53be9d1c..084cb884 100644 --- a/clean/installer/src/wg_core/record.h +++ b/clean/installer/src/wg_core/record.h @@ -108,10 +108,12 @@ void SaveRecord(const wstring& path, const Record& m); bool SaveRebasedRecord(Context& ctx, const wstring& dir, Record& m); wstring Target(const wstring& dir, const wstring& rel); bool HostedRecord(const Record& m); -// 0.6.1: the OptiScaler.ini in `dir` is still the one of WrongGPU's setup: its keys point at WrongGPU's files (FfxDx12SRPath -// at WrongGPU's front end, or Dx12Upscaler at WrongGPU's custom upscaler slot, whichever the record installed). OptiScaler's -// menu saving it keeps them; a file whose keys point elsewhere is another setup's (it replaced or rewrote WrongGPU's): never -// removed or replaced without the player's OK. A record with neither front end: true (nothing to compare). +// 0.6.1: the OptiScaler.ini in `dir` is still the one of WrongGPU's setup: the OptiScaler DLL the record installed is still +// there under its name with its hash (OptiScaler's menu saves the ini with whatever the player picks, the upscaler too), or, +// with that DLL replaced, the ini's keys still point at WrongGPU's files (FfxDx12SRPath at WrongGPU's front end, or +// Dx12Upscaler at WrongGPU's custom upscaler slot, whichever the record installed). Otherwise it is another setup's (its +// OptiScaler replaced WrongGPU's, with its own settings): never removed or replaced without the player's OK. A record with +// neither front end: true (nothing to compare). False without the file. bool OptiIniIsOurs(const wstring& dir, const Record& m); // The hive the Apps & features entries go to (HKEY_CURRENT_USER unless set: the elevated worker of another account sets // the player's hive, HKEY_USERS\). @@ -142,6 +144,9 @@ size_t RemoveRuntimeFiles(const wstring& dir, const wstring& exeDir, const Recor void StartCleanup(Context& ctx, const wstring& state, const wstring& self, const wstring& appData); // keptWarnings (0.6.1): the warning of each recorded file left in place because it changed since the install, by its path (the // update path replaces the warning of a file it then moves aside with the player's OK). +// 0.6.1: a file left in place whose original (from before the install) is in the backup never loses that backup: an +// uninstall keeps the backup folder (with a warning), an update or repair (keepState) refuses before anything changes +// (EXIT_REFUSED), as it does for a file it moved aside that is back with other content. std::vector DoRestore(Context& ctx, const wstring& dir, Ui& ui, bool failedInstall, bool keepState, std::map* keptWarnings = nullptr); // rc6 L4: the player's things in the state folder that a failed install or update never removes when they were there before diff --git a/clean/installer/src/wg_core/test_temp_guard.h b/clean/installer/src/wg_core/test_temp_guard.h deleted file mode 100644 index 0a235a66..00000000 --- a/clean/installer/src/wg_core/test_temp_guard.h +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -// Test builds only: a test program refuses to start when its temp folder is outside the folder the build was configured -// with (CMake WRONGGPU_TEST_TEMP_ROOT -> WG_TEST_TEMP_ROOT; empty: no check), so a test never writes outside it. Checked: -// the TMP and TEMP variables (each when set) and the folder Windows hands out (GetTempPathW). Header only, no wg_core -// dependency (the wizard policy tests use it too). Written for this project. -#pragma once -#include - -#include -#include - -namespace wg_test { - -// path is root or a folder below it: full paths, either slash, any case, never by a bare prefix ("Q:\Root-x" is not below -// "Q:\Root") -inline bool UnderRoot(const std::wstring& path, const std::wstring& root) { - auto full = [](const std::wstring& p) { - wchar_t buf[MAX_PATH * 2] = {}; - const DWORD n = GetFullPathNameW(p.c_str(), MAX_PATH * 2, buf, nullptr); - std::wstring s = n && n < MAX_PATH * 2 ? std::wstring(buf, n) : p; - for (auto& c : s) c = c == L'/' ? L'\\' : (wchar_t)towlower(c); - while (s.size() > 3 && s.back() == L'\\') s.pop_back(); - return s; - }; - if (path.empty() || root.empty()) return false; - const std::wstring p = full(path), r = full(root); - return p == r || (p.size() > r.size() && p.compare(0, r.size(), r) == 0 && (p[r.size()] == L'\\' || r.back() == L'\\')); -} - -// Empty when the temp folder is below root; else why the program refuses. -inline std::wstring TempOutsideRoot(const std::wstring& root) { - if (root.empty()) return std::wstring(); - for (const wchar_t* name : {L"TMP", L"TEMP"}) { - wchar_t v[MAX_PATH * 2] = {}; - const DWORD n = GetEnvironmentVariableW(name, v, MAX_PATH * 2); - if (n && n < MAX_PATH * 2 && !UnderRoot(v, root)) - return std::wstring(L"refused: ") + name + L"=" + v + L" is outside " + root + L" (WRONGGPU_TEST_TEMP_ROOT)"; - } - wchar_t t[MAX_PATH + 1] = {}; - if (!GetTempPathW(MAX_PATH + 1, t) || !UnderRoot(t, root)) - return std::wstring(L"refused: the temp folder ") + t + L" is outside " + root + L" (WRONGGPU_TEST_TEMP_ROOT)"; - return std::wstring(); -} - -#ifdef WG_TEST_TEMP_ROOT -#define WG_TEST_WIDEN2(x) L##x -#define WG_TEST_WIDEN(x) WG_TEST_WIDEN2(x) -inline std::wstring TempGuard() { return TempOutsideRoot(WG_TEST_WIDEN(WG_TEST_TEMP_ROOT)); } -#else -inline std::wstring TempGuard() { return std::wstring(); } -#endif -const int kTempGuardExit = 97; // the exit code of a refused start - -// Writes the refusal to stderr (also from a WIN32 program whose parent gave it one); true when the program must not start. -inline bool TempGuardRefuses() { - const std::wstring why = TempGuard(); - if (why.empty()) return false; - const std::wstring line = why + L"\n"; - const int n = WideCharToMultiByte(CP_UTF8, 0, line.c_str(), (int)line.size(), nullptr, 0, nullptr, nullptr); - std::string u(n > 0 ? n : 0, '\0'); - if (n > 0) WideCharToMultiByte(CP_UTF8, 0, line.c_str(), (int)line.size(), &u[0], n, nullptr, nullptr); - const HANDLE h = GetStdHandle(STD_ERROR_HANDLE); - DWORD done = 0; - if (h && h != INVALID_HANDLE_VALUE) WriteFile(h, u.data(), (DWORD)u.size(), &done, nullptr); - return true; -} - -} // namespace wg_test diff --git a/clean/installer/tests/coexist_061_tests.py b/clean/installer/tests/coexist_061_tests.py index d0309561..93fdd287 100644 --- a/clean/installer/tests/coexist_061_tests.py +++ b/clean/installer/tests/coexist_061_tests.py @@ -1,9 +1,10 @@ # SPDX-License-Identifier: MIT """0.6.1 coexistence fixes (another setup next to WrongGPU's: an OptiScaler that names WrongGPU, other plugins, a changed -OptiScaler.ini, WrongGPU's files in another setup), run by run_coexist_tests.py. +OptiScaler.ini, WrongGPU's files in another setup) and interrupted operations, run by run_coexist_tests.py. Written for this project; Python standard library only. Every file of "another setup" is a synthetic stand-in made here -(coexist_fixtures.py / mockpe.py) or a copy of WrongGPU's own files from a test install; no third-party file is read. +(coexist_fixtures.py / mockpe.py) or a copy of WrongGPU's own files from a test install; no third-party file is read. The +running game is a stand-in program built here from two lines of C (only when cl is on PATH; skipped otherwise). """ import json import os @@ -49,10 +50,10 @@ def with_files(before, root, files): return want -# ---------------------------------------------------------------- fix 1: an OptiScaler that names WrongGPU +# ---------------------------------------------------------------- an OptiScaler that names WrongGPU def test_optiscaler_named_wronggpu(t, opti): - print("\n[0.6.1 fix 1] an OptiScaler whose version resource names WrongGPU is an OptiScaler; ours only by the record's name and hash") + print("\n[0.6.1 coexist] an OptiScaler whose version resource names WrongGPU is an OptiScaler; ours only by the record's name and hash") d = os.path.join(t.work, "fp061") shutil.rmtree(d, ignore_errors=True) files = {"edition-a.dll": (fx.optiscaler_naming_wronggpu(), "optiscaler"), "edition-b.dll": (fx.optiscaler_naming_wronggpu(product_first=False), "optiscaler"), @@ -105,7 +106,7 @@ def test_optiscaler_named_wronggpu(t, opti): shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 3: another setup's OptiScaler over WrongGPU's proxy +# ---------------------------------------------------------------- another setup's OptiScaler over WrongGPU's proxy def older_record(b, version="0.5.1"): p = os.path.join(b, "wronggpu-setup", "install.record") @@ -113,7 +114,7 @@ def older_record(b, version="0.5.1"): def test_proxy_replaced(t, opti): - print("\n[0.6.1 fix 3] another setup's OptiScaler replaced WrongGPU's proxy: Repair / Update ask the switch question first") + print("\n[0.6.1 coexist] another setup's OptiScaler replaced WrongGPU's proxy: Repair / Update ask the switch question first") root, b, exe = lt.game(t, "Proxy Replaced Game", validated=True) before = snapshot(root) rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") @@ -125,7 +126,7 @@ def test_proxy_replaced(t, opti): g = t.j.get("game", {}) t.check("status: the other OptiScaler under WrongGPU's proxy name is \"Asks first\" (ask-switch)", rc == 0 and rc2 == 0 and any(f.get("decision") == "ask-switch" and proxy in f.get("files", []) for f in g.get("coexistence", [])), g.get("coexistence")) - t.check("status: that file is listed by one finding only (WrongGPU's setup says its proxy was replaced; item 10)", + t.check("status: that file is listed by one finding only (WrongGPU's setup says its proxy was replaced)", sum(1 for f in g.get("coexistence", []) if proxy in f.get("files", [])) == 1 and any(f.get("decision") == "managed" and "was replaced" in f.get("what", "") for f in g.get("coexistence", [])), g.get("coexistence")) state = snapshot(root) @@ -161,34 +162,50 @@ def test_proxy_replaced(t, opti): shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 4: OptiScaler.ini is ours only while it points at us +# ---------------------------------------------------------------- OptiScaler.ini: the install's beside its OptiScaler OTHER_SETUP_INI = ("[Upscalers]\r\nDx12Upscaler=xess\r\n[Libraries]\r\nFfxDx12SRPath=C:\\OtherSetup\\upscaler.dll\r\n" "; another setup's OptiScaler.ini (synthetic)\r\n") def test_opti_ini_ownership(t, opti): - print("\n[0.6.1 fix 4] OptiScaler.ini is WrongGPU's only while its keys point at WrongGPU's files") + print("\n[0.6.1 coexist] OptiScaler.ini is WrongGPU's beside WrongGPU's OptiScaler (whatever its menu saved); another setup's with that setup's OptiScaler") root, b, exe = lt.game(t, "Ini Owner Game", validated=True) before = snapshot(root) ini_path = os.path.join(b, "OptiScaler.ini") key = os.path.relpath(ini_path, root).replace("\\", "/").lower() - # OptiScaler's menu saves the ini (WrongGPU's keys kept): still WrongGPU's, removed by the uninstall (rc6 L5) + # OptiScaler's menu saves the ini (WrongGPU's keys kept): still WrongGPU's, removed by the uninstall rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") write(ini_path, read(ini_path) + b"; saved by OptiScaler's menu\r\n") rc2 = t.run("uninstall", exe) t.check("menu-saved OptiScaler.ini (WrongGPU's keys kept): still WrongGPU's, removed with the uninstall", rc == 0 and rc2 == 0 and snapshot(root) == before, diff(before, snapshot(root))) - # another setup rewrote it (its keys point elsewhere): asked first, backed up, left alone without the OK + # the player picked another upscaler in OptiScaler's menu (its keys point elsewhere now), WrongGPU's OptiScaler still in + # place: still WrongGPU's (never "another setup's"), removed by the uninstall rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") write(ini_path, OTHER_SETUP_INI) rc2 = t.run("status", exe) g = t.j.get("game", {}) - t.check("status: an OptiScaler.ini that points elsewhere is another setup's (ask-switch)", rc == 0 and rc2 == 0 and + t.check("status: an OptiScaler.ini the menu pointed elsewhere, beside WrongGPU's OptiScaler, is WrongGPU's (no question for it)", rc == 0 and rc2 == 0 and + not any(f.get("decision") == "ask-switch" for f in g.get("coexistence", [])), g.get("coexistence")) + rc = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall: that ini goes with the rest, no \"another setup changed it\" warning", rc == 0 and snapshot(root) == before and + not any("OptiScaler.ini" in w for w in warns), (warns, diff(before, snapshot(root)))) + # another setup replaced WrongGPU's OptiScaler with its own, and its ini: asked first, backed up, left alone without the OK + rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + proxy = proxy_of(b) + theirs = fx.optiscaler() + pkey = os.path.relpath(os.path.join(b, proxy), root).replace("\\", "/").lower() + write(os.path.join(b, proxy), theirs) + write(ini_path, OTHER_SETUP_INI) + rc2 = t.run("status", exe) + g = t.j.get("game", {}) + t.check("status: with another setup's OptiScaler over WrongGPU's, its OptiScaler.ini is another setup's too (ask-switch)", rc == 0 and rc2 == 0 and any(f.get("decision") == "ask-switch" and "OptiScaler.ini" in f.get("files", []) for f in g.get("coexistence", [])), g.get("coexistence")) state = snapshot(root) rc = repair(t, exe, opti) - t.check("repair without the player's OK: exit 6, nothing changed (the other setup's ini kept)", rc == 6 and snapshot(root) == state, (rc, t.j.get("message"))) + t.check("repair without the player's OK: exit 6, nothing changed (the other setup's files kept)", rc == 6 and snapshot(root) == state, (rc, t.j.get("message"))) rc = repair(t, exe, opti, "--switch") lines = rec_lines(b) if rc == 0 else [] warns = t.j.get("warnings", []) @@ -199,22 +216,68 @@ def test_opti_ini_ownership(t, opti): rc = t.run("uninstall", exe) want = dict(before) want[key] = sha(OTHER_SETUP_INI.encode()) - t.check("uninstall: the other setup's OptiScaler.ini back byte for byte", rc == 0 and snapshot(root) == want, diff(want, snapshot(root))) + want[pkey] = sha(theirs) + t.check("uninstall: the other setup's OptiScaler and OptiScaler.ini back byte for byte", rc == 0 and snapshot(root) == want, diff(want, snapshot(root))) os.remove(ini_path) - # uninstall with it rewritten: left in place, with a warning + os.remove(os.path.join(b, proxy)) + # uninstall with both replaced: left in place, with warnings rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") + proxy = proxy_of(b) + write(os.path.join(b, proxy), theirs) write(ini_path, OTHER_SETUP_INI) rc2 = t.run("uninstall", exe) warns = t.j.get("warnings", []) - t.check("uninstall: an OptiScaler.ini another setup rewrote is left in place with a warning", rc == 0 and rc2 == 0 and + t.check("uninstall: another setup's OptiScaler.ini (beside its OptiScaler) is left in place with a warning", rc == 0 and rc2 == 0 and read(ini_path) == OTHER_SETUP_INI.encode() and any("OptiScaler.ini no longer points at WrongGPU's files" in w for w in warns), warns) shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 5: what the uninstall removes goes by hash +def test_players_ini_edited_in_menu(t, opti): + print("\n[0.6.1 coexist] the player's own OptiScaler.ini (backed up by a switch), then changed in OptiScaler's menu: never lost") + theirs = fx.optiscaler() + players_ini = "[Menu]\r\nShowFps=true\r\n; the player's own OptiScaler.ini (synthetic)\r\n" + root, b, exe = lt.game(t, "Menu Ini Game", validated=True, extra={"bin/x64/winmm.dll": theirs, "bin/x64/OptiScaler.ini": players_ini}) + before = snapshot(root) + ini_path = os.path.join(b, "OptiScaler.ini") + # uninstall after the menu changed the upscaler (keys no longer WrongGPU's): the player's own ini comes back + rc = install(t, exe, opti, "--switch") + rec = "\n".join(rec_lines(b)) + write(ini_path, OTHER_SETUP_INI) + rc2 = t.run("uninstall", exe) + t.check("uninstall after the menu changed the player's switched-over OptiScaler.ini: their own ini and OptiScaler back byte for byte", + rc == 0 and "\tOptiScaler.ini" in rec and rc2 == 0 and snapshot(root) == before, (rc, rc2, t.j.get("message"), t.j.get("warnings"), diff(before, snapshot(root)))) + # Repair after the same menu change: the player's own ini is kept in the new install's backup, and comes back on uninstall + rc = install(t, exe, opti, "--switch") + write(ini_path, OTHER_SETUP_INI) + rc2 = repair(t, exe, opti) + backup = os.path.join(b, "wronggpu-setup", "backup", "OptiScaler.ini") + t.check("repair after that menu change: done, the player's own ini in the new install's backup", rc == 0 and rc2 == 0 and + os.path.isfile(backup) and read(backup) == players_ini.encode(), (rc, rc2, t.j.get("message"))) + rc = t.run("uninstall", exe) + t.check("...uninstall: the player's own ini and OptiScaler back byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + # another setup replaced WrongGPU's OptiScaler and that ini since: the backup of the player's own ini is never deleted. + # Repair refuses before anything changes; the uninstall leaves the other setup's files and keeps the backup folder + rc = install(t, exe, opti, "--switch") + proxy = proxy_of(b) + other = fx.optiscaler_naming_wronggpu() + write(os.path.join(b, proxy), other) + write(ini_path, OTHER_SETUP_INI) + state = snapshot(root) + rc2 = repair(t, exe, opti, "--switch") + t.check("repair --switch with another setup's files over a backed-up original: refused (exit 2, \"Nothing was changed\"), nothing changed", + rc == 0 and rc2 == 2 and "Nothing was changed" in (t.j.get("message") or "") and snapshot(root) == state, (rc, rc2, t.j.get("message"), diff(state, snapshot(root)))) + rc = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall: the other setup's files stay, the player's own ini stays in the kept backup folder (said)", rc == 0 and read(ini_path) == OTHER_SETUP_INI.encode() and + read(os.path.join(b, proxy)) == other and os.path.isfile(backup) and read(backup) == players_ini.encode() and + any(w.startswith("The backup folder was kept") for w in warns), (rc, t.j.get("message"), warns)) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- what the uninstall removes goes by hash def test_uninstall_by_hash(t, opti): - print("\n[0.6.1 fix 5] the uninstall removes a changed file only when its hash is one of WrongGPU's releases") + print("\n[0.6.1 coexist] the uninstall removes a changed file only when its hash is one of WrongGPU's releases") root, b, exe = lt.game(t, "Uninstall Hash Game", validated=True) rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") rt, fe = os.path.join(b, "wronggpu_runtime.dll"), os.path.join(b, "wronggpu_ffx_dx12.dll") @@ -231,9 +294,10 @@ def test_uninstall_by_hash(t, opti): rc2 = t.run("uninstall", exe) t.check("uninstall: a changed file whose hash is a WrongGPU build's is removed with the rest", rc == 0 and rc2 == 0 and not os.path.exists(rt), (rc2, t.j.get("warnings"))) - # another setup's OptiScaler.ini that names WrongGPU's files stays (fix 4) and is warned about + # another setup's OptiScaler.ini that names WrongGPU's files stays and is warned about rc = t.run("install", exe, "--opti=" + opti, "--noscan", "--force") ini = "[Libraries]\r\nFfxDx12SRPath=%s\r\n" % os.path.join(b, "OtherSetup", "wronggpu_ffx_dx12.dll") + write(os.path.join(b, proxy_of(b)), fx.optiscaler()) # (that setup's OptiScaler replaced WrongGPU's: the ini is that setup's) write(os.path.join(b, "OptiScaler.ini"), ini) rc2 = t.run("uninstall", exe) warns = t.j.get("warnings", []) @@ -242,14 +306,14 @@ def test_uninstall_by_hash(t, opti): shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 2: other setups' plugins beside OptiScaler +# ---------------------------------------------------------------- other setups' plugins beside OptiScaler # an RR game: the RR model file stand-in alone (a game that creates RR itself, as run_launcher_tests.py's [direct-rr] game) RR_FILES = {"bin/x64/nvngx_dlssd.dll": b"MZ synthetic stand-in, not a usable RR model file " * 64} def test_other_plugins(t, opti): - print("\n[0.6.1 fix 2] other setups' OptiScaler plugins: WrongGPU's RR stays out by default; moved aside only with the player's OK") + print("\n[0.6.1 coexist] other setups' OptiScaler plugins: WrongGPU's RR stays out by default; moved aside only with the player's OK") other = fx.unknown("another setup's OptiScaler plugin (synthetic .asi)") extra = dict(RR_FILES) extra["bin/x64/plugins/OtherSetup.asi"] = other @@ -274,8 +338,30 @@ def test_other_plugins(t, opti): rc == 0 and any(l.endswith("\\WrongGPU-RR.asi") and l.startswith("copy\t") for l in lines) and "owner\tdisable\tplugins\\OtherSetup.asi\tmoved" in lines and not os.path.exists(os.path.join(b, "plugins", "OtherSetup.asi")) and read(os.path.join(b, "wronggpu-setup", "backup", "plugins", "OtherSetup.asi")) == other and any(w.startswith("Moved aside with your OK: plugins\\OtherSetup.asi") for w in warns), (rc, t.j.get("message"), lines[:20], warns)) + # Repair and Update after "Move them aside": the plugin moved with the OK stays aside, WrongGPU's RR stays in (the + # earlier install's restore brings it back; byte for byte that file goes aside again on that OK) + for verb, more in (("repair", ()), ("update", ())): + if verb == "update": + older_record(b) + rc = repair(t, exe, opti, *more) if verb == "repair" else t.run("update", exe, "--opti=" + opti, "--noscan", "--force") + lines = rec_lines(b) if rc == 0 else [] + t.check(verb + " after \"Move them aside\": the other plugin still aside (recorded, in the backup), WrongGPU's RR plugin still in", + rc == 0 and "owner\tdisable\tplugins\\OtherSetup.asi\tmoved" in lines and not os.path.exists(os.path.join(b, "plugins", "OtherSetup.asi")) and + os.path.isfile(os.path.join(b, "plugins", "WrongGPU-RR.asi")) and read(os.path.join(b, "wronggpu-setup", "backup", "plugins", "OtherSetup.asi")) == other, + (rc, t.j.get("message"), t.j.get("warnings"), lines[:20])) rc = t.run("uninstall", exe) t.check("...uninstall: the other plugin back byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + # a different plugin under the moved name since: never moved without the OK; WrongGPU's RR goes out instead + rc = install(t, exe, opti, "--switch-plugins") + changed = fx.unknown("another plugin put under the moved name since (synthetic .asi)") + write(os.path.join(b, "plugins", "OtherSetup.asi"), changed) + state = snapshot(root) + rc2 = repair(t, exe, opti, "--switch-plugins") + t.check("repair with a different file under a moved plugin's name: refused before anything changes (its moved original's backup is kept)", + rc == 0 and rc2 == 2 and "Nothing was changed" in (t.j.get("message") or "") and snapshot(root) == state, (rc, rc2, t.j.get("message"))) + os.remove(os.path.join(b, "plugins", "OtherSetup.asi")) + rc = t.run("uninstall", exe) + t.check("...uninstall after it was taken away again: the other plugin back byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) # OptiScaler's own plugin folder counts too; a game without RR keeps every plugin beside WrongGPU's (inform only) write(os.path.join(b, "OptiScaler", "plugins", "Second.asi"), other) rc = t.run("coexist", exe) @@ -296,20 +382,21 @@ def test_other_plugins(t, opti): shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 6: WrongGPU's files in another mod's setup +# ---------------------------------------------------------------- WrongGPU's files in another mod's setup def our_files(t, opti): - """WrongGPU's runtime and front end as a hosted install writes them (from a throwaway game).""" + """WrongGPU's runtime and front end as a hosted install writes them (from a throwaway game), and its licence file when + the install writes one (any package that ships WrongGPU's files carries that text).""" root, b, exe = lt.game(t, "Kit Source") install(t, exe, opti) - files = {n: read(os.path.join(b, n)) for n in ("wronggpu_runtime.dll", "wronggpu_ffx_dx12.dll")} + files = {n: read(os.path.join(b, n)) for n in ("wronggpu_runtime.dll", "wronggpu_ffx_dx12.dll", "wronggpu-license.txt") if os.path.isfile(os.path.join(b, n))} t.run("uninstall", exe) shutil.rmtree(root, ignore_errors=True) return files def test_leftovers_other_setup(t, opti): - print("\n[0.6.1 fix 6] WrongGPU's files beside an OptiScaler WrongGPU didn't install: used by another mod's setup, left alone") + print("\n[0.6.1 coexist] WrongGPU's files beside an OptiScaler WrongGPU didn't install: used by another mod's setup, left alone") kit = our_files(t, opti) extra = {"bin/x64/dxgi.dll": fx.optiscaler(), "bin/x64/OptiScaler.ini": "[Menu]\r\n; another mod's setup (synthetic)\r\n"} extra.update({"bin/x64/" + n: d for n, d in kit.items()}) @@ -332,14 +419,33 @@ def test_leftovers_other_setup(t, opti): t.check("uninstall: the other mod's setup back byte for byte (its OptiScaler and WrongGPU's files it used)", rc == 0 and snapshot(root) == state, diff(state, snapshot(root))) rc = t.run("clean-leftovers", exe, "--force") - t.check("clean-leftovers --force (confirmed): the files go", rc == 0 and not any(os.path.exists(os.path.join(b, n)) for n in kit), (rc, t.j.get("message"))) + t.check("clean-leftovers --force: still refused (--force is only the GPU/HIP check's), nothing changed", rc == 2 and snapshot(root) == state, (rc, t.j.get("message"))) + rc = t.run("clean-leftovers", exe, "--confirm-other-setup") + t.check("clean-leftovers --confirm-other-setup (confirmed): the files go", rc == 0 and not any(os.path.exists(os.path.join(b, n)) for n in kit), (rc, t.j.get("message"))) + shutil.rmtree(root, ignore_errors=True) + # the licence file alone never makes them WrongGPU's own setup (any package that ships WrongGPU's files carries it); + # WrongGPU's menu plugin by its hash does + print(" (the kit above %s WrongGPU's licence file)" % ("held" if "wronggpu-license.txt" in kit else "had no")) + root, b, exe = lt.game(t, "Own Setup Lost Record") + rc = install(t, exe, opti) + menu = os.path.join(b, "plugins", "WrongGPU.asi") + has_menu = os.path.isfile(menu) + shutil.rmtree(os.path.join(b, "wronggpu-setup")) # the record is lost + for k, v in t.reg_keys().items(): # ... and its Apps & features entry (test root only) + if k.startswith("WrongGPU-") and v.get("InstallLocation", "").lower().startswith(root.lower()): + subprocess.run(["reg", "delete", t.uninstall + "\\" + k, "/f"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + rc2 = t.run("status", exe, "--noscan") + g = t.j.get("game", {}) + t.check("WrongGPU's own setup that lost its record (its menu plugin there, by its hash): leftovers to clean up, not another mod's setup", + rc == 0 and rc2 == 0 and has_menu and g.get("status") == "leftovers" and not g.get("leftovers_other_setup"), + (rc, has_menu, g.get("status"), g.get("leftovers_other_setup"), [x["path"] for x in g.get("leftovers", [])])) shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 7: WrongGPU's RR plugin is a known leftover +# ---------------------------------------------------------------- WrongGPU's RR plugin is a known leftover def test_rr_plugin_leftover(t, opti): - print("\n[0.6.1 fix 7] leftovers: WrongGPU's RR plugin is recognised (by the embedded payload's and the releases' hashes)") + print("\n[0.6.1 coexist] leftovers: WrongGPU's RR plugin is recognised (by the embedded payload's and the releases' hashes)") root, b, exe = lt.game(t, "Rr Leftover Game", extra=dict(RR_FILES)) rc = install(t, exe, opti) has_rr = os.path.isfile(os.path.join(b, "plugins", "WrongGPU-RR.asi")) @@ -357,10 +463,10 @@ def test_rr_plugin_leftover(t, opti): shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- item 9: the "stays out" card of another upscaler mod +# ---------------------------------------------------------------- the "stays out" card of another upscaler mod def test_stays_out_card(t, opti): - print("\n[0.6.1 item 9] the card of a game with another upscaler mod (never named) reads as a sentence") + print("\n[0.6.1 coexist] the card of a game with another upscaler mod (never named) reads as a sentence") root, b, exe = lt.game(t, "Other Mod Card Game", extra={"bin/x64/" + lt.other_mod_keys()[1][0]: "[mock]\r\n"}) # its marker file dump = os.path.join(t.work, "ui-dump-061.json") rc = t.run("ui-dump", "--dump=" + dump, "--noscan", "--library=" + os.path.join(t.work, "games")) @@ -376,10 +482,10 @@ def test_stays_out_card(t, opti): shutil.rmtree(root, ignore_errors=True) -# ---------------------------------------------------------------- fix 3 follow-up: the switch's OK stands for the same files +# ---------------------------------------------------------------- the switch's OK stands for the same files def test_repair_after_switch(t, opti): - print("\n[0.6.1 fix 3 follow-up] Repair after a switch: the files moved aside with the OK go aside again; a different file is asked about") + print("\n[0.6.1 coexist] Repair after a switch: the files moved aside with the OK go aside again; a different file is asked about") theirs, ini = fx.optiscaler(), "[Menu]\r\nShowFps=true\r\n; the player's\r\n" root, b, exe = lt.game(t, "Switch Repair Game", validated=True, extra={"bin/x64/winmm.dll": theirs, "bin/x64/OptiScaler.ini": ini}) before = snapshot(root) @@ -404,13 +510,214 @@ def test_repair_after_switch(t, opti): shutil.rmtree(root, ignore_errors=True) +# ---------------------------------------------------------------- backups that must be kept; the settings file + +def test_backups_kept(t, opti): + print("\n[0.6.1 coexist] Update, Repair and the move out of a wrong folder never discard a backup of the player's files") + theirs, log_a, log_b = fx.optiscaler(), b"the player's own OptiScaler.log (synthetic)\r\n", b"a log WrongGPU's OptiScaler wrote (synthetic)\r\n" + root, b, exe = lt.game(t, "Kept Log Game", validated=True, extra={"bin/x64/winmm.dll": theirs, "bin/x64/OptiScaler.log": log_a}) + before = snapshot(root) + backup = os.path.join(b, "wronggpu-setup", "backup", "OptiScaler.log") + rc = install(t, exe, opti, "--switch") + t.check("install --switch: the player's OptiScaler.log moved aside with their OptiScaler (in the backup)", rc == 0 and os.path.isfile(backup) and read(backup) == log_a, + (rc, t.j.get("message"))) + # WrongGPU's OptiScaler writes its own OptiScaler.log while the game runs; Update and Repair keep the player's in the backup + for verb in ("update", "repair"): + write(os.path.join(b, "OptiScaler.log"), log_b) + if verb == "update": + older_record(b) + rc = t.run("update", exe, "--opti=" + opti, "--noscan", "--force") + else: + rc = repair(t, exe, opti) + t.check(verb + " after WrongGPU's OptiScaler wrote its log: done, the player's OptiScaler.log still in the backup byte for byte", + rc == 0 and os.path.isfile(backup) and read(backup) == log_a, (rc, t.j.get("message"), t.j.get("warnings"))) + write(os.path.join(b, "OptiScaler.log"), log_b) + rc = t.run("uninstall", exe) + t.check("...uninstall: the player's OptiScaler, and their OptiScaler.log, back byte for byte", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + shutil.rmtree(root, ignore_errors=True) + + # the move out of a wrong folder (an install next to a launcher stub, moved to the game by Repair): when a different file + # is back where the install there moved the player's file aside, the move stops before anything changes + root, b, exe = lt.game(t, "Kept Wrong Folder Game", validated=True, extra={"winmm.dll": theirs}) + stub, starter = os.path.join(root, "REDprelauncher.exe"), os.path.join(root, "Starter.exe") + write(stub, "a launcher stub " * 50) + write(starter, "mock starter exe " * 200) + rc = t.run("install", starter, "--opti=" + opti, "--noscan", "--force", "--experimental", "--switch") + rp = os.path.join(root, "wronggpu-setup", "install.record") + ok = rc == 0 and os.path.isfile(rp) + if ok: + write(rp, read(rp).decode("utf-8").replace("exe\t" + starter + "\r\n", "exe\t" + stub + "\r\n")) + os.remove(starter) + other = fx.optiscaler_naming_wronggpu() + write(os.path.join(root, "winmm.dll"), other) # the player put another OptiScaler there since + state = snapshot(root) + rc2 = t.run("repair", root, "--opti=" + opti, "--noscan", "--force", "--switch") + t.check("repair that moves an install out of a wrong folder, with a different file where the player's was moved aside: refused, nothing changed, backup kept", + rc2 == 2 and "Nothing was changed" in (t.j.get("message") or "") and snapshot(root) == state and + read(os.path.join(root, "wronggpu-setup", "backup", "winmm.dll")) == theirs, (rc2, t.j.get("message"), diff(state, snapshot(root)))) + os.remove(os.path.join(root, "winmm.dll")) + rc3 = t.run("uninstall", root) + t.check("...uninstall there once that file is away: the player's OptiScaler back byte for byte", rc3 == 0 and read(os.path.join(root, "winmm.dll")) == theirs, + (rc3, t.j.get("message"))) + else: + t.check("wrong-folder setup: an install in the game's root", False, (rc, t.j.get("message"))) + drop_test_entries(t, root) + shutil.rmtree(root, ignore_errors=True) + + +def drop_test_entries(t, root): + for k, v in t.reg_keys().items(): # Apps & features entries of games below root (test root only) + if k.startswith("WrongGPU-") and v.get("InstallLocation", "").lower().startswith(root.lower()): + subprocess.run(["reg", "delete", t.uninstall + "\\" + k, "/f"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + +def test_settings_file(t, opti): + print("\n[0.6.1 coexist] wronggpu.ini (WrongGPU's settings) changed by the launcher or by hand: Repair keeps it; uninstall removes it and says so") + root, b, exe = lt.game(t, "Settings File Game", validated=True) + before = snapshot(root) + ini = os.path.join(b, "wronggpu.ini") + rc = install(t, exe, opti) + rc2 = t.run("set", exe, "output_filter=quality9") + write(ini, read(ini) + b"; edited by hand\r\n") + rc3 = repair(t, exe, opti) + t.check("repair after the settings changed (launcher and by hand): done, the hand edit kept", rc == 0 and rc2 == 0 and rc3 == 0 and b"edited by hand" in read(ini), + (rc, rc2, rc3, t.j.get("message"))) + lines = rec_lines(b) + existed = any(l.startswith("copy\t1\t") and l.endswith("\twronggpu.ini") for l in lines) + write(ini, read(ini) + b"; edited again\r\n") + rc = repair(t, exe, opti) + t.check("repair again (wronggpu.ini now over an earlier one, changed again): done, never refused", rc == 0 and b"edited again" in read(ini), (existed, rc, t.j.get("message"))) + write(ini, read(ini) + b"; edited before the uninstall\r\n") + rc = t.run("uninstall", exe) + warns = t.j.get("warnings", []) + t.check("uninstall with a hand-edited wronggpu.ini: removed (the game as before WrongGPU); the result says removed, never \"left in place\"", + rc == 0 and snapshot(root) == before and any(w.startswith("wronggpu.ini had changed") and "removed with the rest" in w for w in warns) and + not any("Left in place" in w and "wronggpu.ini" in w for w in warns), (warns, diff(before, snapshot(root)))) + shutil.rmtree(root, ignore_errors=True) + + +# ---------------------------------------------------------------- interrupted operations + +def _lock(path): + """Opens `path` with no sharing (as a running game holds its DLLs): (handle, close).""" + import ctypes + from ctypes import wintypes + k = ctypes.WinDLL("kernel32", use_last_error=True) + k.CreateFileW.restype = wintypes.HANDLE + k.CreateFileW.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, wintypes.DWORD, wintypes.LPVOID, wintypes.DWORD, wintypes.DWORD, wintypes.HANDLE] + h = k.CreateFileW(path, 0x80000000, 0, None, 3, 0x80, None) # GENERIC_READ, no sharing, OPEN_EXISTING + ok = h not in (None, wintypes.HANDLE(-1).value) + return ok, (lambda: k.CloseHandle(h)) if ok else (lambda: None) + + +def _sleeper(t): + """A tiny program that only waits (built here with cl, when it is on PATH), to stand in for a running game; None without cl.""" + cl = shutil.which("cl") + if not cl: + return None + d = os.path.join(t.work, "sleeper") + os.makedirs(d, exist_ok=True) + src, exe = os.path.join(d, "sleeper.c"), os.path.join(d, "sleeper.exe") + if not os.path.isfile(exe): + write(src, "#include \nint main(void) { Sleep(120000); return 0; }\n") + subprocess.run([cl, "/nologo", "/O1", src, "/Fe:" + exe, "/Fo:" + d + "\\"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + cwd=d, creationflags=0x08000000 | 0x00004000) + return exe if os.path.isfile(exe) else None + + +def test_interrupted(t, opti): + print("\n[0.6.1 coexist] interrupted operations: a locked or read-only file, the game running, a stop part-way: nothing is lost") + other = fx.unknown("another setup's OptiScaler plugin (synthetic .asi)") + extra = dict(RR_FILES) + extra["bin/x64/plugins/OtherSetup.asi"] = other + root, b, exe = lt.game(t, "Interrupted Game", extra=extra) + before = snapshot(root) + rt = os.path.join(b, "wronggpu_runtime.dll") + # a locked file (another program holds it open without sharing): the uninstall stops with the record and backup kept; + # once it is free, the uninstall runs again and the game is as before WrongGPU + rc = install(t, exe, opti, "--switch-plugins") + state = snapshot(root) + ok, unlock = _lock(rt) + try: + rc2 = t.run("uninstall", exe) + finally: + unlock() + t.check("uninstall with a locked WrongGPU file: refused before anything changes (exit 2, \"Nothing was changed\"), record and backup kept", + rc == 0 and ok and rc2 == 2 and "Nothing was changed" in (t.j.get("message") or "") and snapshot(root) == state, (rc, ok, rc2, t.j.get("message"))) + rc = t.run("uninstall", exe) + t.check("...uninstall again once the file is free: the game as before WrongGPU, the other plugin back byte for byte", rc == 0 and snapshot(root) == before, + (rc, t.j.get("message"), diff(before, snapshot(root)))) + # read-only files (WrongGPU's runtime, OptiScaler's ini): the uninstall removes them all the same + rc = install(t, exe, opti, "--switch-plugins") + for p in (rt, os.path.join(b, "OptiScaler.ini")): + os.chmod(p, 0o444) + rc2 = t.run("uninstall", exe) + t.check("uninstall with read-only WrongGPU files: done, the game as before WrongGPU", rc == 0 and rc2 == 0 and snapshot(root) == before, + (rc2, t.j.get("message"), diff(before, snapshot(root)))) + # a stop part-way through a Repair (after the earlier install's restore, the test build's hook): the earlier install is + # undone completely, the moved plugin is back byte for byte, nothing half-installed + rc = install(t, exe, opti, "--switch-plugins") + t.env["WRONGGPU_TEST_FAIL_AFTER_RESTORE"] = "1" + try: + rc2 = repair(t, exe, opti) + finally: + t.env.pop("WRONGGPU_TEST_FAIL_AFTER_RESTORE", None) + now = {k: v for k, v in snapshot(root).items() if "/wronggpu-setup/" not in k} + want = {k: v for k, v in before.items() if "/wronggpu-setup/" not in k} + t.check("repair stopped right after the earlier install's restore: the game's files as before WrongGPU (the other plugin back), no record", + rc == 0 and rc2 != 0 and now == want and not os.path.isfile(os.path.join(b, "wronggpu-setup", "install.record")), (rc2, t.j.get("message"), diff(want, now))) + for f in [os.path.join(dp, n) for dp, _, ns in os.walk(os.path.join(b, "wronggpu-setup")) for n in ns]: + os.remove(f) # (the settings the failed repair kept for a next try) + # an uninstall killed part-way (simulated: the files it removes first are gone, the record and backup are still there): + # run again, it finishes, and the game is as before WrongGPU + rc = install(t, exe, opti, "--switch-plugins") + lines = rec_lines(b) + gone = [l.split("\t")[-1] for l in lines if l.startswith("copy\t0\t")][-2:] + for rel in gone: + if os.path.isfile(os.path.join(b, rel)): + os.remove(os.path.join(b, rel)) + rc2 = t.run("uninstall", exe) + t.check("uninstall after one killed part-way (%s already gone): finishes, the game as before WrongGPU" % ", ".join(gone), rc == 0 and len(gone) == 2 and rc2 == 0 and + snapshot(root) == before, (rc2, t.j.get("message"), diff(before, snapshot(root)))) + # the game running: uninstall and repair refuse before anything changes; once it is closed, the uninstall runs + sleeper = _sleeper(t) + if not sleeper: + print(" (skipped: the game-running cases need cl on PATH to build a stand-in program)") + else: + game_exe = read(exe) + rc = install(t, exe, opti, "--switch-plugins") + shutil.copyfile(sleeper, exe) + state = snapshot(root) + p = subprocess.Popen([exe], creationflags=0x08000000 | 0x00004000) + try: + rc2 = t.run("uninstall", exe) + m2 = t.j.get("message") or "" + rc3 = repair(t, exe, opti) + m3 = t.j.get("message") or "" + same = snapshot(root) == state + finally: + p.kill() + p.wait() + t.check("game running: uninstall and repair refused (exit 2, \"is running\"), nothing changed", rc == 0 and rc2 == 2 and rc3 == 2 and + "is running" in m2 and "is running" in m3 and same, (rc2, m2, rc3, m3)) + write(exe, game_exe) + rc = t.run("uninstall", exe) + t.check("...closed: the uninstall runs, the game as before WrongGPU", rc == 0 and snapshot(root) == before, diff(before, snapshot(root))) + print(" (a full disk is not simulated: it cannot be done safely here without filling a real drive)") + shutil.rmtree(root, ignore_errors=True) + + def run_all(t, opti, full): test_optiscaler_named_wronggpu(t, opti) test_proxy_replaced(t, opti) test_repair_after_switch(t, opti) test_opti_ini_ownership(t, opti) + test_players_ini_edited_in_menu(t, opti) test_uninstall_by_hash(t, opti) test_other_plugins(t, opti) test_leftovers_other_setup(t, opti) test_rr_plugin_leftover(t, opti) test_stays_out_card(t, opti) + test_backups_kept(t, opti) + test_settings_file(t, opti) + test_interrupted(t, opti) diff --git a/clean/installer/tests/coexist_tests.cpp b/clean/installer/tests/coexist_tests.cpp index 8ca2829c..2c566538 100644 --- a/clean/installer/tests/coexist_tests.cpp +++ b/clean/installer/tests/coexist_tests.cpp @@ -13,7 +13,6 @@ #include "wg_core/logtail.h" #include "wg_core/optikeys.h" #include "wg_core/record.h" -#include "wg_core/test_temp_guard.h" using namespace wg; @@ -34,7 +33,7 @@ wstring TempFolder() { void Put(const wstring& path, const string& data) { EnsureDir(Parent(path)); WriteFileAtomic(path, data.data(), data.size()); } Tool ToolOf(const string& bytes, const wstring& name = L"") { return IdentifyBytes((const uint8_t*)bytes.data(), bytes.size(), name).tool; } string Utf16(const char* s) { string r; for (; *s; ++s) { r += *s; r += '\0'; } return r; } -// 0.6.1 (gap 4): a minimal PE32+ DLL whose export table names `names` (Microsoft's public PE/COFF documentation, ".edata"; as +// 0.6.1: a minimal PE32+ DLL whose export table names `names` (Microsoft's public PE/COFF documentation, ".edata"; as // tests/mockpe.py _export_table): never loaded, only read. Every function points at the section start. void Le(string& b, uint64_t v, int n) { for (int i = 0; i < n; ++i) b += char((v >> (8 * i)) & 0xFF); } string ExportDll(const std::vector& names) { @@ -74,9 +73,8 @@ bool Has(const std::vector& v, const wstring& s) { for (auto& x : v) if } // namespace int main() { - if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root try { - // ---- 0.6.1 fix 7: the 0.6.0 release's files, the RR plugin among them, are known (known_releases.h) ------------ + // ---- 0.6.1: the 0.6.0 release's files, the RR plugin among them, are known (known_releases.h) ------------------ { int rows060 = 0; bool rrPlugin = false; @@ -743,98 +741,12 @@ int main() { for (auto& w : all.warnings) { xessWarn |= w.kind == L"xess-no-depth"; plug |= w.kind == L"plugin-not-hooked"; } require(all.found && xessWarn && plug && all.plugin == L"not-hooked", "ReadLastRun: XeSS without depth (OptiScaler.log), the plugin's log in its own folder"); - // ---- 0.6.1 RR follow-up 1: the RR plugin's guard line (HOOK-MODE.md, "Another Ray Reconstruction plugin") in Last run -------- - { - const string head = "21:00:00.000 load: process 4242 attached C:\\Games\\Example\\plugins\\WrongGPU-RR.asi (hook mode)\r\n"; - // the guard's lines as HOOK-MODE.md ("Log lines") gives them, right after the time stamp - const string otherText = "another Ray Reconstruction plugin is active; WrongGPU RR stays off (synthetic detail; nothing patched; " - "rr_other_plugin=take in wronggpu-rr.ini uses WrongGPU's instead)"; - const string other = "21:00:00.100 " + otherText + "\r\n"; - LastRun g1; - ParseRrLog(head + other, g1); - require(g1.rrFound && !g1.rrUsed && g1.rrGuard == FromUtf8(otherText), "RR guard: another RR plugin: its whole line after the time stamp"); - const char* const finals[] = { - "another Ray Reconstruction plugin is active; WrongGPU RR stays off (synthetic detail; it loaded after WrongGPU: WrongGPU passes every call on " - "unchanged; to use WrongGPU RR, move it aside)", - "a second copy of WrongGPU RR is loaded (C:\\Games\\Example\\plugins\\WrongGPU-RR.asi is active); this copy " - "(C:\\Games\\Example\\OptiScaler\\plugins\\Kit.asi) stays off", - "a plugin loaded after WrongGPU replaced its hooks; rr_other_plugin=take cannot be applied: WrongGPU RR stays off and passes every call on " - "unchanged (synthetic detail); move it aside to use WrongGPU RR"}; - for (const char* line : finals) { - LastRun gx; - ParseRrLog(head + "21:00:01.000 " + line + "\r\n", gx); - require(gx.rrGuard == FromUtf8(line), "RR guard: each of the guard's final lines is found, whole"); - } - // take mode (rr_other_plugin=take): WrongGPU RR goes in front of the other plugin and is on: never a guard line - LastRun take; - ParseRrLog(head + "21:00:00.100 another Ray Reconstruction plugin is active; rr_other_plugin=take: WrongGPU RR goes in front of it " - "(synthetic detail; it gets the game's other calls, no RR work)\r\n", take); - require(take.rrFound && take.rrGuard.empty() && !take.rrGuardOff, "RR guard: the take mode's line is not WrongGPU RR off"); - { - const wstring td = Join(dir, L"rr-guard-take"); - Put(Join(td, L"wronggpu-rr.log"), head + "21:00:00.100 another Ray Reconstruction plugin is active; rr_other_plugin=take: WrongGPU RR goes in " - "front of it (synthetic detail)\r\n21:00:30.000 runtime: create instance 1: output 1920x1080, render 960x540\r\n"); - const LastRun tr = ReadLastRun(td); - bool guardWarn = false; - for (auto& w : tr.warnings) guardWarn |= w.kind == L"rr-guard"; - require(tr.found && tr.rrUsed && !tr.rrGuardOff && !guardWarn && tr.Summary().find(L"stayed off") == wstring::npos, - "RR guard: a take-mode run where RR was asked for: an RR run, no guard warning, never \"stayed off\""); - } - LastRun older; - ParseRrLog(head + other + "21:05:00.000 load: process 4343 attached (hook mode)\r\n", older); - require(older.rrFound && older.rrGuard.empty(), "RR guard: an earlier session's guard line is not the last session's"); - LastRun none; - ParseRrLog(head + "21:00:00.100 RR provider registered with the host (plugin interface 5)\r\n", none); - require(none.rrGuard.empty(), "RR guard: none without its line"); - // read as the launcher reads a game's folder: the RR log alone, the guard kept WrongGPU RR off: a run that says why - const wstring gd = Join(dir, L"rr-guard"); - Put(Join(gd, L"wronggpu-rr.log"), head + other); - const LastRun gr = ReadLastRun(gd); - bool shown = false; - for (auto& w : gr.warnings) shown |= w.kind == L"rr-guard" && w.text == g1.rrGuard; - require(gr.found && gr.rrOnly && !gr.rrUsed && !gr.created && shown && !gr.AnyUpscaled() && gr.Summary().rfind(L"Ray Reconstruction: WrongGPU RR stayed off", 0) == 0, - "RR guard: the RR log alone with the guard line: a run (RR-only, nothing upscaled), the guard line among its warnings, the summary says RR stayed off"); - // with RR frames before a later plugin replaced the hooks: the frames count, the guard line shows too - const string replaced = "21:00:30.000 runtime: create instance 1: output 1920x1080, render 960x540\r\n" - "21:01:00.000 runtime: instance 1 timing, 300 frames from frame 1: GPU 2.000 ms per frame (pre 0.010), render 960x540, output 1920x1080\r\n" - "21:01:05.000 a plugin loaded after WrongGPU replaced its hooks; rr_other_plugin=take cannot be applied: WrongGPU RR stays " - "off and passes every call on unchanged (synthetic detail); move it aside to use WrongGPU RR\r\n"; - Put(Join(gd, L"wronggpu-rr.log"), head + replaced); - const LastRun gf = ReadLastRun(gd); - shown = false; - for (auto& w : gf.warnings) shown |= w.kind == L"rr-guard" && w.text.rfind(L"a plugin loaded after WrongGPU replaced its hooks", 0) == 0; - require(gf.found && gf.rrUsed && gf.rrFrames == 300 && gf.upscaled && shown, "RR guard: RR frames and then the hooks replaced: the run's frames, and the guard line"); - Put(Join(gd, L"wronggpu-rr.log"), head + "21:00:00.100 RR provider registered with the host (plugin interface 5)\r\n"); - require(!ReadLastRun(gd).found, "RR guard: no guard line, no RR request: still not a run"); - - // the game list's startup cache (library-list.txt: LastRunCacheFlags, and the guard line in a field of its own): read - // back, the run is the same for the tile and the page from the start (0.6.1) - require(gr.rrGuardOff && !gr.RrAlone() && !gf.rrGuardOff && gf.RrAlone(), - "RR guard: the guard kept WrongGPU RR off: no Ray Reconstruction alone in the run (the banner's words); frames before the hooks were replaced: RR alone"); - auto cached = [](const LastRun& live) { - LastRun c; - require(ReadLastRunCacheFlags(LastRunCacheFlags(live), c), "startup cache: the flags read back"); - c.when = live.when; c.rrGuard = live.rrGuard; // (their own fields of the list) - return c; - }; - const LastRun cg = cached(gr), cf = cached(gf); - require(LastRunCacheFlags(gr) == L"1000101" && cg.found && cg.rrOnly && cg.rrGuardOff && !cg.RrAlone() && cg.rrGuard == gr.rrGuard && - cg.Summary() == gr.Summary() && !cg.AnyUpscaled(), - "startup cache: a guard run read back is still a guard run (flag, line, summary; no RR alone, nothing upscaled)"); - require(!cf.rrGuardOff && cf.RrAlone() && cf.upscaled && cf.rrGuard == gf.rrGuard, "startup cache: RR frames, then the hooks replaced: as it was"); - LastRun old6, bad; - require(ReadLastRunCacheFlags(L"100011", old6) && old6.found && old6.rrOnly && old6.rrUpscaled && !old6.rrGuardOff, - "startup cache: a list of an earlier build (6 flags) is read, without the guard flag"); - require(!ReadLastRunCacheFlags(L"10", bad) && !ReadLastRunCacheFlags(L"10x0101", bad) && !ReadLastRunCacheFlags(L"10001010", bad), - "startup cache: flags of another length or with other characters are not read"); - } - - // ---- 0.6.1 RR follow-up 2 (gap 4): a plugin exporting WrongGPU RR's marker is WrongGPU's own, whatever its name or hash ----- + // ---- 0.6.1: a plugin exporting WrongGPU RR's marker is WrongGPU's own, whatever its name or hash ----- { string hdr; require(ReadAll(Join(FromUtf8(WG_TEST_LOGS), L"..\\..\\..\\rr_f\\proxy\\include\\wg_rr_settings_contract.h"), hdr), "the RR settings contract header is there"); require(hdr.find(string("#define WG_RR_CONTRACT_EXPORT \"") + kRrContractExport + "\"") != string::npos, - "gap 4: kRrContractExport is the RR plugin's WG_RR_CONTRACT_EXPORT (wg_rr_settings_contract.h)"); + "RR marker: kRrContractExport is the RR plugin's WG_RR_CONTRACT_EXPORT (wg_rr_settings_contract.h)"); const wstring kitDir = Join(dir, L"kit-game"), x = Join(kitDir, L"Game.exe"); Put(x, "MZ synthetic game"); const string kit = ExportDll({"WrongGPU_RrOther", kRrContractExport}), plain = ExportDll({"InitPlugin", "WrongGPU_RrOther"}); @@ -845,12 +757,12 @@ int main() { require(ExportsRrContract(Join(kitDir, L"plugins\\KitRR.asi")) && ExportsRrContract(Join(kitDir, L"OptiScaler\\plugins\\renamed.asi")) && !ExportsRrContract(Join(kitDir, L"plugins\\Other.asi")) && !ExportsRrContract(Join(kitDir, L"plugins\\Words.asi")) && !ExportsRrContract(Join(kitDir, L"plugins\\Missing.asi")), - "gap 4: the marker from the PE export table (never its text alone, never a missing file)"); + "RR marker: the marker from the PE export table (never its text alone, never a missing file)"); const auto ourKit = OurPluginsFromOtherPackages(kitDir, nullptr), foreign = ForeignPlugins(kitDir, nullptr); require(ourKit.size() == 2 && Has(ourKit, L"plugins\\KitRR.asi") && Has(ourKit, L"OptiScaler\\plugins\\renamed.asi"), - "gap 4: both copies are WrongGPU RR from another package"); + "RR marker: both copies are WrongGPU RR from another package"); require(foreign.size() == 2 && Has(foreign, L"plugins\\Other.asi") && Has(foreign, L"plugins\\Words.asi"), - "gap 4: they are not other setups' plugins (so never moved aside); the others still are"); + "RR marker: they are not other setups' plugins (so never moved aside); the others still are"); Context ctx; ctx.logFile = Join(dir, L"kit.log"); const CoexistReport r = AssessCoexistence(ctx, x, kitDir, nullptr); @@ -858,16 +770,57 @@ int main() { for (auto& f : r.findings) if (f.what == L"WrongGPU RR (from another package)") kf = &f; require(kf && kf->tool == Tool::WrongGPU && kf->decision == Decision::Inform && kf->files.size() == 2 && kf->evidence.find(FromUtf8(kRrContractExport)) != wstring::npos, - "gap 4: the rules table shows them as \"WrongGPU RR (from another package)\" (inform, by the export)"); + "RR marker: the rules table shows them as \"WrongGPU RR (from another package)\" (inform, by the export)"); require(r.foreignPlugins == foreign && !Has(r.foreignPlugins, L"plugins\\KitRR.asi") && IsFile(Join(kitDir, L"plugins\\KitRR.asi")), - "gap 4: the report's other-setup plugins (what an install moves aside with the OK) leave them out"); + "RR marker: the report's other-setup plugins (what an install moves aside with the OK) leave them out"); // only those copies: an install folder with just WrongGPU RR from another package has no other-setup plugins at all DeleteFileW(Join(kitDir, L"plugins\\Other.asi").c_str()); DeleteFileW(Join(kitDir, L"plugins\\Words.asi").c_str()); - require(AssessCoexistence(ctx, x, kitDir, nullptr).foreignPlugins.empty(), "gap 4: only WrongGPU RR copies: nothing for an install to move aside"); + require(AssessCoexistence(ctx, x, kitDir, nullptr).foreignPlugins.empty(), "RR marker: only WrongGPU RR copies: nothing for an install to move aside"); + } + + // ---- 0.6.1: what an install moves aside of other setups' plugins (PlanPluginsAside) ------------------------------ + { + const wstring g = Join(dir, L"plan-game"), exeDir = Join(g, L"bin\\x64"); + const string a = "another setup's plugin A (synthetic)", b = "another setup's plugin B (synthetic)"; + Put(Join(exeDir, L"plugins\\A.asi"), a); + Put(Join(exeDir, L"plugins\\B.asi"), b); + const std::vector both = {L"plugins\\A.asi", L"plugins\\B.asi"}; + // the player agreed to the plugins the question listed: exactly those move, a plugin not listed keeps RR out + PluginPlan p = PlanPluginsAside(exeDir, exeDir, both, both, {}); + require(p.moveAside == both && p.blocking.empty() && !p.outside, "plugin plan: both listed and agreed: both moved aside, RR goes in"); + p = PlanPluginsAside(exeDir, exeDir, both, {L"plugins\\A.asi"}, {}); + require(p.moveAside.size() == 1 && IEq(p.moveAside[0], L"plugins\\A.asi") && p.blocking.size() == 1 && IEq(p.blocking[0], L"plugins\\B.asi"), + "plugin plan: a plugin the question didn't list is never moved; it keeps RR out"); + p = PlanPluginsAside(exeDir, exeDir, both, {}, {}); + require(p.moveAside.empty() && p.blocking == both, "plugin plan: no OK: nothing moved, RR out"); + // a Repair after "Move them aside": the plugins the earlier install moved aside are back from its backup; byte for + // byte those go aside again on that OK, a different file under that name is asked about + const std::map before = {{L"plugins\\a.asi", Sha256Bytes(a.data(), a.size())}, {L"plugins\\b.asi", Sha256Bytes(a.data(), a.size())}}; + p = PlanPluginsAside(exeDir, exeDir, both, {}, before); + require(p.moveAside.size() == 1 && IEq(p.moveAside[0], L"plugins\\A.asi") && p.blocking.size() == 1 && IEq(p.blocking[0], L"plugins\\B.asi"), + "plugin plan: moved before with the OK: the same file goes aside again; another file under a moved name keeps RR out"); + // the install folder above the exe folder: the paths moved are the install folder's + p = PlanPluginsAside(exeDir, g, both, both, {}); + require(p.moveAside.size() == 2 && IEq(p.moveAside[0], L"bin\\x64\\plugins\\A.asi") && p.blocking.empty(), + "plugin plan: install folder above the exe folder: moved by their paths in the install folder"); + const std::map beforeSplit = {{L"bin\\x64\\plugins\\a.asi", Sha256Bytes(a.data(), a.size())}}; + p = PlanPluginsAside(exeDir, g, {L"plugins\\A.asi"}, {}, beforeSplit); + require(p.moveAside.size() == 1 && IEq(p.moveAside[0], L"bin\\x64\\plugins\\A.asi"), "plugin plan: install folder above the exe folder: moved before, by that path"); + // the exe folder outside the install folder: nothing can be moved, so RR stays out (never RR beside them) + p = PlanPluginsAside(exeDir, Join(dir, L"elsewhere"), both, both, {}); + require(p.moveAside.empty() && p.blocking == both && p.outside, "plugin plan: exe folder outside the install folder: nothing moved, RR out"); + p = PlanPluginsAside(exeDir, Join(g, L"bin\\x6"), both, both, {}); // (a folder whose name is a prefix of the exe folder's) + require(p.moveAside.empty() && p.outside, "plugin plan: never by a bare name prefix"); + // the record of the install folder names WrongGPU's own plugin by its path there + Record rec; + Entry own; own.action = L"copy"; own.rel = L"bin\\x64\\plugins\\A.asi"; own.inst = Sha256Bytes(a.data(), a.size()); rec.e.push_back(own); + const auto fp = ForeignPlugins(exeDir, &rec, g); + require(fp.size() == 1 && IEq(fp[0], L"plugins\\B.asi"), "plugin plan: a record of the install folder names its plugins by their paths there"); + require(ForeignPlugins(exeDir, &rec, Join(dir, L"elsewhere")).size() == 2, "plugin plan: a record of another folder names none of them"); } - // ---- 0.6.1 RR follow-up 3 (gap 5a): the install folder is not the exe folder: the exe folder's record names its plugins --- + // ---- 0.6.1: the install folder is not the exe folder: the exe folder's record names its plugins --- { const wstring root = Join(dir, L"split-game"), exeDir = Join(root, L"bin\\x64"), x = Join(exeDir, L"Game.exe"); Put(x, "MZ synthetic game"); @@ -881,15 +834,15 @@ int main() { Context ctx; ctx.logFile = Join(dir, L"split.log"); require(AssessCoexistence(ctx, x, root, nullptr).foreignPlugins.empty(), - "gap 5a: install folder above the exe folder: WrongGPU's RR .asi that the exe folder's record installed is not another setup's"); + "split folders: install folder above the exe folder: WrongGPU's RR .asi that the exe folder's record installed is not another setup's"); Put(Join(exeDir, L"plugins\\Other.asi"), "another setup's plugin (synthetic)"); const auto both = AssessCoexistence(ctx, x, root, nullptr).foreignPlugins; - require(both.size() == 1 && IEq(both[0], L"plugins\\Other.asi"), "gap 5a: ...another setup's plugin there still is"); - // gap 5b's other half: with the record, an RR .asi changed since the install (not the file installed) is not ours + require(both.size() == 1 && IEq(both[0], L"plugins\\Other.asi"), "split folders: ...another setup's plugin there still is"); + // with the record, an RR .asi changed since the install (not the file installed) is not ours Put(Join(exeDir, L"plugins\\WrongGPU-RR.asi"), rrAsi + " changed"); - require(Has(ForeignPlugins(exeDir, &rec), L"plugins\\WrongGPU-RR.asi"), "gap 5b: an RR .asi that is no longer the installed file is not counted as ours"); + require(Has(ForeignPlugins(exeDir, &rec), L"plugins\\WrongGPU-RR.asi"), "RR plugin changed: an RR .asi that is no longer the installed file is not counted as ours"); Put(Join(exeDir, L"plugins\\WrongGPU-RR.asi"), rrAsi); - require(!Has(ForeignPlugins(exeDir, &rec), L"plugins\\WrongGPU-RR.asi"), "gap 5b: the installed file with the record: ours"); + require(!Has(ForeignPlugins(exeDir, &rec), L"plugins\\WrongGPU-RR.asi"), "RR plugin changed: the installed file with the record: ours"); } RemoveTree(dir); diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index 550e6b8c..91f6df11 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -19,7 +19,6 @@ #include "wg_core/pe.h" #include "wg_core/profile.h" #include "wg_core/record.h" -#include "wg_core/test_temp_guard.h" #include "wg_core/rr.h" #include "wg_core/rrconfig.h" #include "wg_core/settings.h" @@ -96,7 +95,6 @@ string MockDll(const std::vector>& strings, const st } // namespace int main() { - if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root try { // ---- validation ----------------------------------------------------------------------------------------- string n; wstring why; @@ -338,8 +336,8 @@ int main() { require(!refused && !IsFile(Join(newDir, L"wronggpu_runtime.dll")) && !IsDir(StateDir(newDir)) && IsFile(Join(newDir, L"Game.exe")), "moved game: the uninstall works in the new folder"); - // ---- 0.6.1 (b): a hand-placed WrongGPU DLL under the game's FSR name (a direct install) goes only when the game's - // original is there to put back (the backup, or the kept *.wronggpu-original.dll); else it stays, with a warning ---- + // ---- a hand-placed WrongGPU DLL under the game's FSR name (a direct install) goes only when the game's + // original is there to put back (the backup, or the kept *.wronggpu-original.dll); else the uninstall refuses ---- { const FfxSlot& sl = kSlots[0]; const string orig = "the game's own FidelityFX DLL (synthetic)", installed = "WrongGPU's FSR DLL as installed (synthetic)"; @@ -360,7 +358,7 @@ int main() { }; wstring info; require(ClassifySlot(sl, [&] { const wstring p = Join(dir, L"slot-probe.dll"); file(p, hand); return p; }(), nullptr, info) == FFX_OURS, - "(b): the hand-placed DLL is WrongGPU's by its version resource (the synthetic PE is read)"); + "hand-placed FSR DLL: the hand-placed DLL is WrongGPU's by its version resource (the synthetic PE is read)"); for (int how = 0; how < 2; ++how) { // the original from the backup, then from the kept copy alone const wstring d = direct(how ? L"Kept Copy" : L"Backup", how == 0, true); std::vector w; @@ -368,27 +366,126 @@ int main() { try { w = DoRestore(mc, d, quiet, false, false); } catch (const SetupError&) { threw = true; } string now; require(!threw && ReadAll(Join(d, sl.name), now) && now == orig && !IsFile(Join(d, sl.original)) && !IsDir(StateDir(d)), - how ? "(b): no backup, the kept copy there: the hand-placed DLL is replaced by the game's original" - : "(b): the backup there: the hand-placed DLL is replaced by the game's original"); + how ? "hand-placed FSR DLL: no backup, the kept copy there: the hand-placed DLL is replaced by the game's original" + : "hand-placed FSR DLL: the backup there: the hand-placed DLL is replaced by the game's original"); } - { + { // neither the backup nor the kept copy: the uninstall refuses, as before 0.6.1 ("Nothing was changed") const wstring d = direct(L"No Original", false, false); - std::vector w; bool threw = false; - try { w = DoRestore(mc, d, quiet, false, false); } catch (const SetupError&) { threw = true; } + wstring msg; + try { DoRestore(mc, d, quiet, false, false); } catch (const SetupError& ex) { threw = true; msg = ex.msg; } string now; - bool warned = false; - for (auto& x : w) warned = warned || (x.rfind(L"Left in place: " + wstring(sl.name), 0) == 0 && x.find(L"isn't in the backup") != wstring::npos); - require(!threw && ReadAll(Join(d, sl.name), now) && now == hand && warned && IsFile(Join(d, L"Game.exe")) && !IsFile(RecordPath(d)), - "(b): no original anywhere: the uninstall leaves the DLL under the game's name, with a warning, and removes the rest"); + require(threw && msg.find(L"Nothing was changed") != wstring::npos && ReadAll(Join(d, sl.name), now) && now == hand && IsFile(RecordPath(d)) && + IsFile(Join(d, L"Game.exe")), + "game FSR DLL, no original anywhere: the uninstall refuses (\"Nothing was changed\"), the DLL and the record stay"); const wstring u = direct(L"No Original Update", false, false); threw = false; try { DoRestore(mc, u, quiet, false, true); } catch (const SetupError&) { threw = true; } require(threw && ReadAll(Join(u, sl.name), now) && now == hand && IsFile(RecordPath(u)), - "(b): no original anywhere, an update's restore: refused, nothing changed (record kept)"); + "game FSR DLL, no original anywhere, an update's restore: refused, nothing changed (record kept)"); + } + } + // ---- 0.6.1: a file left in place whose original is in the backup never loses that backup ---------------------- + { + const string mine = "the player's own file from before WrongGPU (synthetic)", ours = "WrongGPU's file as installed (synthetic)", + other = "another setup's file put here since (synthetic)", moved = "a plugin moved aside with the OK (synthetic)"; + auto keptGame = [&](const wstring& name, bool disable) { + const wstring d = Join(dir, L"Kept Backup\\" + name); + file(Join(d, L"Game.exe"), "MZ"); + file(Join(d, disable ? L"plugins\\Other.asi" : L"other.dll"), other); + file(BackupPath(d, disable ? L"plugins\\Other.asi" : L"other.dll"), disable ? moved : mine); + Record m; m.version = L"0.6.0"; m.format = 2; m.game = d; m.exe = Join(d, L"Game.exe"); m.status = L"experimental"; m.model = L"m.wgcm"; + Entry e; e.action = disable ? L"disable" : L"copy"; e.rel = disable ? L"plugins\\Other.asi" : L"other.dll"; e.existed = true; + e.orig = disable ? Sha256Bytes(moved.data(), moved.size()) : Sha256Bytes(mine.data(), mine.size()); + if (!disable) e.inst = Sha256Bytes(ours.data(), ours.size()); + e.owner = disable ? L"moved" : L"wg"; + m.e.push_back(e); + SaveRecord(RecordPath(d), m); + return d; + }; + for (int disable = 0; disable < 2; ++disable) { + const wstring rel = disable ? L"plugins\\Other.asi" : L"other.dll"; + const wstring u = keptGame(disable ? L"Update Moved" : L"Update Copy", disable == 1); + bool threw = false; + wstring msg; + try { DoRestore(mc, u, quiet, false, true); } catch (const SetupError& ex) { threw = true; msg = ex.msg; } + string now, kept; + require(threw && msg.rfind(L"Nothing was changed", 0) == 0 && ReadAll(Join(u, rel), now) && now == other && IsFile(RecordPath(u)) && + ReadAll(BackupPath(u, rel), kept) && kept == (disable ? moved : mine), + disable ? "kept backup: an update's restore with another file where one was moved aside: refused before anything changes" + : "kept backup: an update's restore with another file over a backed-up original: refused before anything changes"); + const wstring d = keptGame(disable ? L"Uninstall Moved" : L"Uninstall Copy", disable == 1); + std::vector w; + threw = false; + try { w = DoRestore(mc, d, quiet, false, false); } catch (const SetupError&) { threw = true; } + bool said = false; + for (auto& x : w) said = said || x.rfind(L"The backup folder was kept", 0) == 0; + require(!threw && said && ReadAll(Join(d, rel), now) && now == other && ReadAll(BackupPath(d, rel), kept) && kept == (disable ? moved : mine), + disable ? "kept backup: the uninstall leaves the other file and keeps the moved file's backup, and says so" + : "kept backup: the uninstall leaves the other file and keeps the original's backup, and says so"); + } + // WrongGPU's settings file over an earlier one (an entry that existed), changed since (the launcher's settings, or + // edited by hand): an update keeps it for the new install, never refused; an uninstall removes it and says so + // (never "left in place"), and the backup folder goes as usual + auto settingsGame = [&](const wstring& name) { + const wstring d = Join(dir, L"Settings Ini\\" + name); + const string before = "[fsr]\r\nupscaler=network\r\n; an earlier one\r\n", installed = "[fsr]\r\nupscaler=network\r\n"; + file(Join(d, L"Game.exe"), "MZ"); + file(Join(d, L"wronggpu.ini"), "[fsr]\r\nupscaler=network\r\noutput_filter=quality9\r\n"); // changed since the install + file(BackupPath(d, L"wronggpu.ini"), before); + Record m; m.version = L"0.6.0"; m.format = 2; m.game = d; m.exe = Join(d, L"Game.exe"); m.status = L"experimental"; m.model = L"m.wgcm"; + Entry e; e.action = L"copy"; e.rel = L"wronggpu.ini"; e.existed = true; e.orig = Sha256Bytes(before.data(), before.size()); + e.inst = Sha256Bytes(installed.data(), installed.size()); e.owner = L"wg"; + m.e.push_back(e); + SaveRecord(RecordPath(d), m); + return d; + }; + { + const wstring u = settingsGame(L"Update"); + std::vector w; + bool threw = false; + try { w = DoRestore(mc, u, quiet, false, true); } catch (const SetupError&) { threw = true; } + string now; + bool leftInPlace = false; + for (auto& x : w) leftInPlace = leftInPlace || x.find(L"wronggpu.ini") != wstring::npos; + require(!threw && ReadAll(Join(u, L"wronggpu.ini"), now) && now.find("quality9") != string::npos && !leftInPlace && !IsFile(RecordPath(u)), + "settings file: an update's restore keeps the changed wronggpu.ini for the new install, no refusal, no warning"); + const wstring d = settingsGame(L"Uninstall"); + w.clear(); + threw = false; + try { w = DoRestore(mc, d, quiet, false, false); } catch (const SetupError&) { threw = true; } + bool saidRemoved = false, saidKept = false; + for (auto& x : w) { + saidRemoved = saidRemoved || (x.rfind(L"wronggpu.ini had changed", 0) == 0 && x.find(L"removed with the rest") != wstring::npos); + saidKept = saidKept || (x.find(L"Left in place") != wstring::npos && x.find(L"wronggpu.ini") != wstring::npos); + } + require(!threw && saidRemoved && !saidKept && !IsFile(Join(d, L"wronggpu.ini")) && !IsDir(StateDir(d)), + "settings file: an uninstall removes the changed wronggpu.ini and says it was removed (never \"left in place\")"); + } + // a log the OptiScaler of WrongGPU's setup wrote over the player's moved-aside OptiScaler.log: an update's restore + // puts the player's back (never refused, never the backup lost) + { + const string players = "the player's own OptiScaler.log (synthetic)", wrote = "a log WrongGPU's OptiScaler wrote (synthetic)", + optiIni = "[Upscalers]\r\nDx12Upscaler=auto\r\n"; + const wstring d = Join(dir, L"Moved Log\\Update"); + file(Join(d, L"Game.exe"), "MZ"); + file(Join(d, L"OptiScaler.log"), wrote); + file(BackupPath(d, L"OptiScaler.log"), players); + file(Join(d, L"OptiScaler.ini"), optiIni); + Record lr; lr.version = L"0.6.0"; lr.format = 2; lr.game = d; lr.exe = Join(d, L"Game.exe"); lr.status = L"experimental"; lr.model = L"m.wgcm"; + Entry optiEntry; optiEntry.action = L"copy"; optiEntry.rel = L"OptiScaler.ini"; optiEntry.inst = Sha256Bytes(optiIni.data(), optiIni.size()); optiEntry.owner = L"wg-optibundle"; + lr.e.push_back(optiEntry); + Entry lg; lg.action = L"disable"; lg.rel = L"OptiScaler.log"; lg.existed = true; lg.orig = Sha256Bytes(players.data(), players.size()); lg.owner = L"moved"; + lr.e.push_back(lg); + SaveRecord(RecordPath(d), lr); + bool threw = false; + try { DoRestore(mc, d, quiet, false, true); } catch (const SetupError&) { threw = true; } + string now; + require(!threw && ReadAll(Join(d, L"OptiScaler.log"), now) && now == players, + "moved-aside OptiScaler.log: the log WrongGPU's OptiScaler wrote goes, the player's comes back (an update is not refused)"); } } - // ---- 0.6.1 RR follow-up 3 (gap 5b): an update that now leaves RR out (the game no longer uses it, or another setup's + // ---- 0.6.1: an update that now leaves RR out (the game no longer uses it, or another setup's // plugin keeps it out) first runs the earlier install's restore with keepState (DoInstall step 2): the earlier RR plugin // goes with it when it is the file installed; one changed since is left in place with a warning, never removed ---- { @@ -409,7 +506,7 @@ int main() { bool threw = false; try { DoRestore(mc, d, quiet, false, true); } catch (const SetupError&) { threw = true; } require(!threw && !IsFile(Join(d, L"plugins\\WrongGPU-RR.asi")) && !IsFile(Join(d, L"wronggpu-rr.ini")) && IsFile(Join(d, L"Game.exe")), - "gap 5b: an update's restore removes the earlier install's RR plugin and its settings (the new install then places none)"); + "RR update: an update's restore removes the earlier install's RR plugin and its settings (the new install then places none)"); const wstring c = earlier(L"Changed"); file(Join(c, L"plugins\\WrongGPU-RR.asi"), "another build put here since (synthetic)"); std::vector w; @@ -417,7 +514,7 @@ int main() { try { w = DoRestore(mc, c, quiet, false, true); } catch (const SetupError&) { threw = true; } bool warned = false; for (auto& x : w) warned = warned || x == L"Left in place (changed since install): plugins\\WrongGPU-RR.asi"; - require(!threw && IsFile(Join(c, L"plugins\\WrongGPU-RR.asi")) && warned, "gap 5b: an RR plugin changed since the install: left in place, with a warning"); + require(!threw && IsFile(Join(c, L"plugins\\WrongGPU-RR.asi")) && warned, "RR update: an RR plugin changed since the install: left in place, with a warning"); } // the scan takes managed folders whose record is gone off the list, unless their drive isn't connected wstring offline; diff --git a/clean/installer/tests/wg_core_tests.cpp b/clean/installer/tests/wg_core_tests.cpp index 5fc69b5f..0ed749ac 100644 --- a/clean/installer/tests/wg_core_tests.cpp +++ b/clean/installer/tests/wg_core_tests.cpp @@ -12,7 +12,6 @@ #include "wg_core/model.h" #include "wg_core/record.h" #include "wg_core/settings.h" -#include "wg_core/test_temp_guard.h" using namespace wg; @@ -33,15 +32,7 @@ wstring TempFolder() { } // namespace int main() { - if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root try { - // 0.6.1: the test programs' temp-folder guard (test_temp_guard.h): below the root by full path, never by a bare prefix - require(wg_test::UnderRoot(L"Q:\\work\\tmp\\x", L"Q:\\work") && wg_test::UnderRoot(L"q:/work/TMP/", L"Q:\\work\\") && - wg_test::UnderRoot(L"Q:\\work", L"Q:\\work"), "temp guard: a folder below the root (either slash, any case), the root itself"); - require(!wg_test::UnderRoot(L"Q:\\work-x\\tmp", L"Q:\\work") && !wg_test::UnderRoot(L"C:\\Windows\\Temp", L"Q:\\work") && - !wg_test::UnderRoot(L"Q:\\work\\..\\other", L"Q:\\work") && !wg_test::UnderRoot(L"", L"Q:\\work"), - "temp guard: not by a bare prefix, not another drive, not out by .., not an empty path"); - require(wg_test::TempOutsideRoot(L"").empty(), "temp guard: no root configured, no check"); // strings and paths require(Join(L"C:\\a", L"b") == L"C:\\a\\b" && Join(L"C:\\a\\", L"b") == L"C:\\a\\b" && Join(L"", L"b") == L"b", "Join"); require(Parent(L"C:\\a\\b.exe") == L"C:\\a" && BaseName(L"C:\\a\\b.exe") == L"b.exe" && Stem(L"C:\\a\\b.exe") == L"b", "Parent/BaseName/Stem"); diff --git a/clean/installer/tests/wizard_policy_tests.cpp b/clean/installer/tests/wizard_policy_tests.cpp index d8b3627b..407d761a 100644 --- a/clean/installer/tests/wizard_policy_tests.cpp +++ b/clean/installer/tests/wizard_policy_tests.cpp @@ -1,11 +1,9 @@ // SPDX-License-Identifier: MIT #include "../src/wizard_policy.h" -#include "../src/wg_core/test_temp_guard.h" #include #include int main() { - if (wg_test::TempGuardRefuses()) return wg_test::kTempGuardExit; // never a temp folder outside the configured root using namespace wg_wizard; int checks = 0; auto require = [&](bool ok, const char* message) { diff --git a/clean/installer/tools/make_known_releases.py b/clean/installer/tools/make_known_releases.py index f1c9a3aa..e43fc6d9 100644 --- a/clean/installer/tools/make_known_releases.py +++ b/clean/installer/tools/make_known_releases.py @@ -6,7 +6,8 @@ python make_known_releases.py --out src/wg_core/known_releases.h [--keep ] = ... The payload folders are our own release builds (build/release//payload*; 0.6.0: build/release-060-rc/payload and -its RR folder rr). Only .dll, .asi and wronggpu-*.txt files are listed. A hash that two releases share is listed once, with +its RR folder rr; its six rows match the files of the published 0.6.0 release by size and SHA-256: the payload its +launcher embeds, and the licence and notices files of its zip). Only .dll, .asi and wronggpu-*.txt files are listed. A hash that two releases share is listed once, with the earlier version. --keep: the rows of an existing header come first, unchanged (a new release added without rebuilding the older folders). Written for this project; Python standard library only. """ From 9f638f10c78ff5208a68c6633fc026000e7af9d0 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:11:55 -0500 Subject: [PATCH 3/7] Launcher coexist: one file-ownership rule for every restore path Every restore, uninstall, repair, update, move out of a wrong folder and cleanup now follows one rule (record.h, README "What the launcher removes or overwrites"): - A file is deleted or overwritten only when its current bytes are WrongGPU's: the hash the record says WrongGPU last wrote there, or a WrongGPU release's or the embedded payload's. Not by name, a neighbouring file, an ini key or because it is a log. The two exceptions: the game's FSR DLL slots (WrongGPU's DLL by its version resource) and settings/log/text files with WrongGPU's own unique names that the record lists as created by WrongGPU. - Anything else at a recorded path stays as it is. A player's original that cannot go back because of it is kept, byte for byte, in \WrongGPU-originals\