From 8e22bc72c94f619bf39c11c9777a6402ae1cc26a Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:51:49 -0500 Subject: [PATCH] Launcher: the Model L choice (set model=L), off by default A launcher built with WRONGGPU_MODEL_L (CMake option, default OFF: on only in a release whose front end and runtime run Model L) has a model setting (profile key `model`, values m and l): - `set model=L` is accepted only while Model L's data on this PC (model\L\model.wgcm) passes its check against Model L's converter data; otherwise it is refused with how to convert it (exit 5, nothing changed). - L writes wronggpu.ini's runtime_options (every model item out, model=L last) and OptiScaler.ini's UpscalerIndex ([WrongGPU] in OptiScaler 10's slot, else [FSR]) to Model L's entry: 1, or 2 in a build with Preset K. Both go through the settings apply, so the install record's hashes follow them. - M changes nothing: only Model L's items and an UpscalerIndex naming Model L's entry go back; profile.ini has a model line only for L. - A game saved on L whose data is gone is not refused on an install, repair or update: its files say Model M with a warning, the profile keeps L. Without the option nothing changes anywhere (no setting in the profile, `get` or the JSON); `set model=L` is refused by name (exit 10). The window has no model control yet. Tests: model-choice (new ctest: profile.cpp built with the choice on, added to the CI launcher step), launcher-core (the choice off), and tests/run_model_l_tests.py --launcher-choice end to end. The shadowed local in the Model L message (model.cpp) is renamed. Refs #89 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 4 +- clean/installer/CMakeLists.txt | 20 ++- clean/installer/README.md | 21 ++++ clean/installer/src/wg_core/launcher.cpp | 22 +++- clean/installer/src/wg_core/model.cpp | 17 ++- clean/installer/src/wg_core/model.h | 7 ++ clean/installer/src/wg_core/profile.cpp | 48 +++++++- clean/installer/src/wg_core/profile.h | 14 ++- clean/installer/src/wizard_policy.h | 6 + clean/installer/tests/launcher_core_tests.cpp | 16 +++ clean/installer/tests/model_choice_tests.cpp | 101 +++++++++++++++ clean/installer/tests/run_model_l_tests.py | 115 +++++++++++++++++- 12 files changed, 375 insertions(+), 16 deletions(-) create mode 100644 clean/installer/tests/model_choice_tests.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58424210..bc6cb476 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,8 +115,8 @@ jobs: run: | $PSNativeCommandUseErrorActionPreference = $true cmake -S clean/installer -B out/launcher-tests -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DWRONGGPU_PAYLOAD_DIR="$PWD/out/no-payload" -DWRONGGPU_TESTING=OFF -DWRONGGPU_PRESET_K=OFF -DWRONGGPU_DIRECT_ROUTE=OFF - cmake --build out/launcher-tests --target wg-core-tests launcher-core-tests coexist-core-tests convert-ignore-tests - ctest --test-dir out/launcher-tests --output-on-failure -R "^(wg-core|launcher-core|coexist-core|convert-ignore|source-size|wording)$" + cmake --build out/launcher-tests --target wg-core-tests launcher-core-tests coexist-core-tests convert-ignore-tests model-choice-tests + ctest --test-dir out/launcher-tests --output-on-failure -R "^(wg-core|launcher-core|coexist-core|convert-ignore|model-choice|source-size|wording)$" rr-plugin: name: "CPU: Ray Reconstruction plugin" diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index bca556bb..ea6077d0 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -54,6 +54,13 @@ else() set(PRESET_K_MAP_FILE) set(PRESET_K_DEFINITION WRONGGPU_PRESET_K=0) endif() +# The Model L choice in the launcher (src/wizard_policy.h): ON only for a release whose front end and runtime run Model L. +option(WRONGGPU_MODEL_L "The Model L choice in the launcher (model=L, the OptiScaler entry); OFF = no model setting" OFF) +if(WRONGGPU_MODEL_L) + set(MODEL_L_DEFINITION WRONGGPU_MODEL_L=1) +else() + set(MODEL_L_DEFINITION WRONGGPU_MODEL_L=0) +endif() option(WRONGGPU_DIRECT_ROUTE "The direct FSR route in the installer (the wizard's advanced choice, /DIRECTFSR, a silent install without /OPTISCALER=); OFF = OptiScaler is required" ON) if(WRONGGPU_DIRECT_ROUTE) set(DIRECT_ROUTE_PAYLOAD_ARGS) @@ -119,6 +126,8 @@ add_library(wg_core STATIC src/wg_core/rrconfig.cpp src/wg_core/convert_ignore.cpp) target_include_directories(wg_core PUBLIC src) target_compile_definitions(wg_core PUBLIC ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION}) +# (private: model-choice-tests compiles profile.cpp with the Model L choice on, against this library) +target_compile_definitions(wg_core PRIVATE ${MODEL_L_DEFINITION}) if(WRONGGPU_TESTING) target_compile_definitions(wg_core PUBLIC WRONGGPU_TESTING) endif() @@ -184,7 +193,7 @@ add_executable(WrongGPU WIN32 src/app/main.cpp src/app/wizard.cpp src/app/cli.cp add_dependencies(WrongGPU WrongGPU-Restore) if(WRONGGPU_TESTING) add_executable(wizard-policy-tests tests/wizard_policy_tests.cpp) - target_compile_definitions(wizard-policy-tests PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION}) + target_compile_definitions(wizard-policy-tests PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_DEFINITION}) endif() # wg_core's unit tests (strings and paths, install record, wronggpu.ini keys, the log file; no game, payload or GPU). add_executable(wg-core-tests tests/wg_core_tests.cpp) @@ -193,6 +202,7 @@ target_link_libraries(wg-core-tests PRIVATE wg_core) # job files, the update reply, the game environment; no game, payload or GPU). add_executable(launcher-core-tests tests/launcher_core_tests.cpp) target_link_libraries(launcher-core-tests PRIVATE wg_core) +target_compile_definitions(launcher-core-tests PRIVATE ${MODEL_L_DEFINITION}) # The coexistence tests (M2): fingerprints on synthetic bytes, the proxy picker, byte-exact OptiScaler.ini edits and the # inikey journal, the OptiScaler tab's key rules, the record's inikey and coexist lines, the log warnings. add_executable(coexist-core-tests tests/coexist_tests.cpp) @@ -209,14 +219,20 @@ add_test(NAME source-size COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_D # The launcher's words never claim the same output as the original ("bit for bit", "identical", "(native)": rr-notes.md) add_test(NAME wording COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_wording.py) add_test(NAME wg-core COMMAND wg-core-tests) +# The Model L choice (profile.cpp with WRONGGPU_MODEL_L on, whatever this build's switch): the model setting, wronggpu.ini's +# model item and OptiScaler's UpscalerIndex. Its own copy of profile.cpp comes first; the rest is wg_core. +add_executable(model-choice-tests tests/model_choice_tests.cpp src/wg_core/profile.cpp) +target_compile_definitions(model-choice-tests PRIVATE WRONGGPU_MODEL_L=1) +target_link_libraries(model-choice-tests PRIVATE wg_core) add_test(NAME launcher-core COMMAND launcher-core-tests) +add_test(NAME model-choice COMMAND model-choice-tests) add_test(NAME coexist-core COMMAND coexist-core-tests) add_test(NAME convert-ignore COMMAND convert-ignore-tests) if(WRONGGPU_TESTING) add_test(NAME wizard-policy COMMAND wizard-policy-tests) endif() target_include_directories(WrongGPU PRIVATE ${GEN}) -target_compile_definitions(WrongGPU PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION}) +target_compile_definitions(WrongGPU PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_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) if(MSVC) target_compile_options(WrongGPU PRIVATE /Zi) diff --git a/clean/installer/README.md b/clean/installer/README.md index be0c3882..e471cafc 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -386,6 +386,27 @@ model choice and the runtime settings for Model L are not part of this step. `te end to end: once with a build of the shipped map, and once with a build of a test map in its exact layout (`--write-test-map`). +**The model choice** (#89; CMake `WRONGGPU_MODEL_L`, default `OFF`, on only in a release whose front end and runtime run +Model L; `src/wizard_policy.h`). With it off there is no model setting anywhere (profile, `get`, the window), and +`set model=L` is refused by name (exit 10). With it on, `set model=L|M` (profile key `model`, values `m`, `l`): +- **L** is accepted only while Model L's data on this PC (`model\L\model.wgcm`) passes its check against Model L's converter + data. Otherwise: "Model L can't be chosen. Model L's data on this PC is not ready (...). Convert it first: ..." (exit 5, + nothing changed). It writes wronggpu.ini's `runtime_options`: every model item out, `model=L` last (the last model item + wins). It also writes OptiScaler.ini's `UpscalerIndex`, so OptiScaler starts with Model L's entry: `[WrongGPU]` in + OptiScaler 10's slot, else `[FSR]`. The index is 1, or 2 in a build with Preset K (after Model M and Model K in the + front end's list). Both writes go through the settings apply, so the install record's hashes follow them, as for every + settings write. +- **M** is the default and changes nothing. Model L's items become `model=M` again, and an `UpscalerIndex` naming Model + L's entry goes back to 0. Anything else (the installer's `model=M`, another entry the player chose in OptiScaler's + menu) stays as it is. profile.ini has a `model` line only for L. +- A game saved on L whose Model L data is gone (removed, or not converted before an install, repair or update) is not + refused. Its files say Model M with a warning saying how to convert the data, and the profile keeps L. +- The window has no model control yet. The choice is made with `set` (or a `profile.model=` line of an elevated job). + +Tested by `model-choice` (ctest: profile.cpp built with the choice on) and `tests/run_model_l_tests.py --launcher-choice` +(a build with the choice on: refusal, both files, record hashes, back to M byte for byte, repair without the data, +uninstall), and with it off by `launcher-core` and the same script's build without the choice. + **Ignore lists** (`src/wg_core/convert_ignore.*`): WrongGPU converts only the vendor DLL files that came with the player's own games, never a copy that another program's installer placed in a game. Such an installer registers the files it placed in a list the launcher always reads, and the player does nothing. Every search for a file to convert (the model and the Ray diff --git a/clean/installer/src/wg_core/launcher.cpp b/clean/installer/src/wg_core/launcher.cpp index 6377073d..694d39ec 100644 --- a/clean/installer/src/wg_core/launcher.cpp +++ b/clean/installer/src/wg_core/launcher.cpp @@ -15,6 +15,7 @@ #include "gamerules.h" #include "json_writer.h" +#include "model.h" #include "optiscaler.h" #include "payload.h" #include "pe.h" @@ -754,6 +755,18 @@ void ApplyProfile(Context& ctx, const wstring& dir, const Profile& p, std::vecto if (!LoadRecord(RecordPath(dir), m) || m.legacy) Fail(L"WrongGPU is not installed in " + dir + L".", EXIT_NOT_INSTALLED); InferOwners(ctx, m); bool recordChanged = m.format < 2; + // Model L saved while its data on this PC is not ready (removed since, or an install of a game set to L before the data + // was converted): the game's files say Model M until it is; the profile keeps the player's choice + Profile q = p; + if (p.get("model") == "l") { + wstring why; + if (!ModelFileReady(ctx, L'L', &why)) { + q.v["model"] = "m"; + const wstring w = ModelLNotReady(why) + L" Until then the game starts on Model M."; + notes.push_back(w); + if (warnings) warnings->push_back(w); + } + } auto renderFile = [&](const wchar_t* name, bool opti) { const wstring path = Join(dir, name); string in; @@ -761,7 +774,7 @@ void ApplyProfile(Context& ctx, const wstring& dir, const Profile& p, std::vecto if (opti && !had) return; // OptiScaler.ini: only an existing file (ours) is changed string out; wstring why; if (opti) { - RenderOptiIni(p, in, out, ¬es); + RenderOptiIni(q, in, out, ¬es); bool wrote = false; out = RenderGameOptiKeys(p, m.exe, out, m.inikeys, notes, &wrote); if (wrote) @@ -769,7 +782,7 @@ void ApplyProfile(Context& ctx, const wstring& dir, const Profile& p, std::vecto JournalChanges(m.inikeys, name, in, out); recordChanged = recordChanged || out != in; } - else if (!RenderWronggpuIni(p, in, out, &why)) Fail(L"Settings not applied: " + why, EXIT_USAGE); + else if (!RenderWronggpuIni(q, in, out, &why)) Fail(L"Settings not applied: " + why, EXIT_USAGE); if (out == in && (had || out.empty())) return; // unchanged, or nothing to write into a missing file WriteFileAtomic(path, out.data(), out.size()); const wstring h = Sha256Bytes(out.data(), out.size()); @@ -1107,6 +1120,11 @@ OpResult RunOp(Context& ctx, const OpRequest& r, Ui& ui) { res.message = L"Engine.ini setting applied; it takes effect the next time the game starts"; break; } + // Model L chosen now (it was not the game's model before): only with its data on this PC; nothing changes otherwise + if (!r.optiOnly && r.hasProfile && r.profile.get("model") == "l" && GameProfile(r.dir).get("model") != "l") { + wstring why; + if (!ModelFileReady(ctx, L'L', &why)) Fail(L"Model L can't be chosen. " + ModelLNotReady(why) + L" Nothing was changed.", EXIT_NO_MODEL); + } if (!r.optiOnly) ApplyProfile(ctx, r.dir, r.hasProfile ? r.profile : GameProfile(r.dir), res.notes, &res.warnings); ApplyOptiTab(ctx, r.dir, r, res.notes); res.message = L"Settings applied; they take effect the next time the game starts"; diff --git a/clean/installer/src/wg_core/model.cpp b/clean/installer/src/wg_core/model.cpp index 388629e0..708df5c4 100644 --- a/clean/installer/src/wg_core/model.cpp +++ b/clean/installer/src/wg_core/model.cpp @@ -23,6 +23,17 @@ bool ExistingModelValid(Context& ctx, wstring* why, wgc::ModelFileInfo* info) { if (why) *why = FromUtf8(w); return ok; } +// One model's file on this PC checked against that model's own converter data, whatever model ctx has selected (it is +// selected again afterwards). False: `why` says what is missing or wrong. +bool ModelFileReady(Context& ctx, wchar_t preset, wstring* why) { + const wchar_t was = SelectedPreset(ctx); + if (was == preset) return ExistingModelValid(ctx, why); + wstring err; + if (!SelectPreset(ctx, wstring(1, preset), err)) { if (why) *why = err; return false; } + const bool ok = ExistingModelValid(ctx, why); + SelectPreset(ctx, wstring(1, was), err); + return ok; +} // True when a valid model file may lack a group of this map (preset M, map version 4: the output-filter weights). bool MapHasOptionalGroup(const wgc::Map& map) { for (auto& st : map.stages) if (st.optional()) return true; @@ -210,11 +221,11 @@ ModelState FindModel(Context& ctx, const GameTarget* t, const wstring& userDll, const wstring skippedText = skipped ? L" " + std::to_wstring(skipped) + L" file(s) on an ignore list were not tried. " + IgnoredExample(ctx, m.ignored) : wstring(); if (ctx.presetL) { // Model L: said by name, with the converter's reason for the file the player chose const wstring picked = userDll.empty() ? wstring() : FullPath(userDll); - wstring why; + wstring pickedWhy; for (auto& r : m.rejections) - if (!picked.empty() && r.size() > picked.size() + 2 && IEq(r.substr(0, picked.size() + 2), picked + L": ")) { why = r.substr(picked.size() + 2); break; } + if (!picked.empty() && r.size() > picked.size() + 2 && IEq(r.substr(0, picked.size() + 2), picked + L": ")) { pickedWhy = r.substr(picked.size() + 2); break; } m.error = L"Model L can't be prepared: no DLSS model file with Model L's data was found." + - (why.empty() ? wstring() : L" The file you chose (" + picked + L"): " + why) + + (pickedWhy.empty() ? wstring() : L" The file you chose (" + picked + L"): " + pickedWhy) + L" Model L is converted from the DLSS model file (nvngx_dlss.dll) of version 310.5 or newer. The file stays where it is: " L"only the model data is read, on this PC." + skippedText + (m.chosenSkipped.empty() ? wstring() : L" " + m.chosenSkipped); LogLine(ctx, L"model: " + m.error); diff --git a/clean/installer/src/wg_core/model.h b/clean/installer/src/wg_core/model.h index f92be3e7..94bfee22 100644 --- a/clean/installer/src/wg_core/model.h +++ b/clean/installer/src/wg_core/model.h @@ -43,6 +43,13 @@ struct ModelCandidate { wstring path, origin; }; wstring ReadModelSource(Context& ctx); bool ExistingModelValid(Context& ctx, wstring* why = nullptr, wgc::ModelFileInfo* info = nullptr); +// One model's file (L'M', L'L', ...) checked against that model's converter data, whatever model ctx has selected. +bool ModelFileReady(Context& ctx, wchar_t preset, wstring* why = nullptr); +// The player's lines for Model L chosen while its data on this PC is not ready (`why`: ModelFileReady's reason). +inline wstring ModelLNotReady(const wstring& why) { + return L"Model L's data on this PC is not ready (" + why + L"). Convert it first: WrongGPU.exe model convert --preset=L " + L"(optionally --model=)."; +} bool MapHasOptionalGroup(const wgc::Map& map); wstring FilterText(Context& ctx, bool present); std::vector ModelCandidates(const GameTarget* t, const wstring& userDll, const std::vector& libraries); diff --git a/clean/installer/src/wg_core/profile.cpp b/clean/installer/src/wg_core/profile.cpp index 386c28c1..2a05199a 100644 --- a/clean/installer/src/wg_core/profile.cpp +++ b/clean/installer/src/wg_core/profile.cpp @@ -40,6 +40,12 @@ const SettingDef kSettings[] = { // (not decided yet: the launcher asks after the install) and off leave the file alone. {"rr_config_fix", Layer::Rr, Tier::Advanced, "ask", "ask|on|off", L"Ray Reconstruction engine setting", L"On: WrongGPU adds the one Engine.ini line this game's Ray Reconstruction needs (and takes it out again on uninstall)."}, +#if WRONGGPU_MODEL_L + // Model L (#89; only in a release whose front end and runtime run it): the model the game starts with. L needs Model L's + // data on this PC (model\L\model.wgcm, checked against Model L's converter data); M changes nothing in the game's files. + {"model", Layer::Model, Tier::Basic, "m", "m|l", L"Model", + L"M: Model M (default). L: Model L, converted from a DLSS file of version 310.5 or newer that has it."}, +#endif }; const size_t kSettingCount = sizeof(kSettings) / sizeof(kSettings[0]); @@ -150,7 +156,10 @@ string ProfileText(const Profile& p) { string t = "; WrongGPU launcher: the settings of this game. The launcher writes wronggpu.ini (and OptiScaler.ini)\r\n" "; from this file; change them in the launcher or with: WrongGPU.exe set key=value\r\n" "[profile]\r\nformat=1\r\n"; - for (auto& d : kSettings) t += string(d.key) + "=" + p.get(d.key) + "\r\n"; + for (auto& d : kSettings) { + if (d.layer == Layer::Model && p.isDefault(d.key)) continue; // Model M: profile.ini as before the model choice + t += string(d.key) + "=" + p.get(d.key) + "\r\n"; + } for (auto& kv : p.v) if (!FindSetting(kv.first)) t += kv.first + "=" + kv.second + "\r\n"; return t; } @@ -163,6 +172,7 @@ void SaveProfile(const wstring& path, const Profile& p) { bool SetSetting(Profile& p, const string& keyIn, const string& value, wstring* why) { const string key = LowerA(TrimA(keyIn)); const SettingDef* d = FindSetting(key); + if (!d && key == "model") { if (why) *why = kNoModelChoice; return false; } // a build without the Model L choice if (!d) { if (why) *why = L"unknown setting \"" + FromUtf8(keyIn) + L"\""; return false; } string n; if (!ValidateSetting(*d, value, &n, why)) return false; @@ -246,6 +256,11 @@ std::map EffectiveSettings(const string& wronggpuIni, const stri if (!d || d->layer != Layer::Rt) continue; eff[k] = ProfileFromRuntime(k, kv.second); } + if (FindSetting("model")) { // the last model item of runtime_options (the one the front end uses): Model L or not + string model; + for (auto& kv : SplitOptions(options)) if (LowerA(kv.first) == "model") model = LowerA(kv.second); + eff["model"] = model == "l" ? "l" : "m"; + } string fps; if (IniHasKey(optiIni, "Menu", "ShowFps", &fps)) { const string l = LowerA(fps); @@ -288,6 +303,19 @@ bool RenderWronggpuIni(const Profile& p, const string& in, string& out, wstring* const string rv = RuntimeValue(d.key, p.get(d.key)); if (!p.isDefault(d.key) && !rv.empty()) items.push_back({d.key, rv}); } + // the model (WRONGGPU_MODEL_L builds): L, every model item out and model=L last (the last model item wins); M, only Model + // L's items go back to model=M (the installer's model=M, and Model K's item of a build with it, stay as they are) + if (FindSetting("model")) { + auto isModel = [](const std::pair& kv) { return LowerA(kv.first) == "model"; }; + if (p.get("model") == "l") { + std::vector> kept; + for (auto& kv : items) if (!isModel(kv)) kept.push_back(kv); + kept.push_back({"model", "L"}); + items = kept; + } else { + for (auto& kv : items) if (isModel(kv) && LowerA(kv.second) == "l") kv.second = "M"; + } + } const string joined = JoinOptions(items); // the line is rewritten only when its items change (a player's spacing and comment stay otherwise) if (hadOptions ? joined != JoinOptions(SplitOptions(options)) : !joined.empty()) text = IniSet(text, hadOptions ? section : "fsr", "runtime_options", joined); @@ -297,14 +325,28 @@ bool RenderWronggpuIni(const Profile& p, const string& in, string& out, wstring* bool RenderOptiIni(const Profile& p, const string& in, string& out, std::vector* notes) { out = in; + // the model (WRONGGPU_MODEL_L builds): the entry of WrongGPU's list OptiScaler starts with. OptiScaler 10's custom + // upscaler slot: [WrongGPU] UpscalerIndex; else [FSR] UpscalerIndex (the list of WrongGPU's FFX DLL). L: Model L's entry; + // M: back to Model M's entry (0) only when the file names Model L's (another value, such as Model K's, stays). + if (FindSetting("model")) { + string cur; + const char* sec = IniHasKey(out, "WrongGPU", "UpscalerIndex", &cur) ? "WrongGPU" : IniHasKey(out, "FSR", "UpscalerIndex", &cur) ? "FSR" : nullptr; + if (sec) { + cur = TrimA(cur); + if (p.get("model") == "l" && cur != kModelLEntryIndex) out = IniSet(out, sec, "UpscalerIndex", kModelLEntryIndex); + else if (p.get("model") != "l" && cur == kModelLEntryIndex) out = IniSet(out, sec, "UpscalerIndex", "0"); + } else if (p.get("model") == "l" && notes) { + notes->push_back(L"Model L: this OptiScaler.ini has no UpscalerIndex key; choose WrongGPU Model L in OptiScaler's menu"); + } + } const string fps = p.get("fps_overlay"); if (fps == "keep") return true; string cur; - if (!IniHasKey(in, "Menu", "ShowFps", &cur)) { + if (!IniHasKey(out, "Menu", "ShowFps", &cur)) { if (notes) notes->push_back(L"OptiScaler FPS overlay: this OptiScaler build has no [Menu] ShowFps key; not changed"); return true; } - out = IniSet(in, "Menu", "ShowFps", fps == "on" ? "true" : "false"); + out = IniSet(out, "Menu", "ShowFps", fps == "on" ? "true" : "false"); return true; } diff --git a/clean/installer/src/wg_core/profile.h b/clean/installer/src/wg_core/profile.h index 1dcb7841..61a1bf82 100644 --- a/clean/installer/src/wg_core/profile.h +++ b/clean/installer/src/wg_core/profile.h @@ -10,7 +10,9 @@ namespace wg { // wronggpu.ini [fsr] key, runtime_options item, OptiScaler.ini key, the RR plugin's WrongGPU\wronggpu.ini [wronggpu] key // (Ray Reconstruction games only, rr.h: RenderRrSettings writes them; wronggpu.ini and OptiScaler.ini never hold them) -enum class Layer { Fe, Rt, Opti, Rr }; +// Model: the model the game starts with (WRONGGPU_MODEL_L builds only): wronggpu.ini's runtime_options model item and the +// OptiScaler entry OptiScaler starts with (UpscalerIndex); with M nothing is changed in either file. +enum class Layer { Fe, Rt, Opti, Rr, Model }; enum class Tier { Basic, Advanced, Diagnostics }; // One setting of the profile. Values are the profile's own words ("on", "off", ...); Render maps them to the file. @@ -45,6 +47,16 @@ void SaveProfile(const wstring& path, const Profile& p); wstring ProfilePath(const wstring& installDir); // `set` and the UI: one key; false with *why for an unknown key or a bad value. bool SetSetting(Profile& p, const string& key, const string& value, wstring* why); +// The refusal of the model setting in a build without the Model L choice (WRONGGPU_MODEL_L off). +inline const wchar_t* const kNoModelChoice = + L"Model L isn't part of this build of WrongGPU: it comes with a release that runs Model L. The game stays on Model M."; +// The index of Model L's entry in the list of upscalers WrongGPU's front end gives OptiScaler (its UpscalerIndex): after +// Model M and, in a build with Preset K, Model K. +#if WRONGGPU_PRESET_K +inline const char* const kModelLEntryIndex = "2"; +#else +inline const char* const kModelLEntryIndex = "1"; +#endif // ---- wronggpu.ini -------------------------------------------------------------------------------------------- // The runtime_options items in order (split at ';', trimmed, empty items dropped). diff --git a/clean/installer/src/wizard_policy.h b/clean/installer/src/wizard_policy.h index 9341e326..72cf29f3 100644 --- a/clean/installer/src/wizard_policy.h +++ b/clean/installer/src/wizard_policy.h @@ -11,6 +11,12 @@ #ifndef WRONGGPU_DIRECT_ROUTE #define WRONGGPU_DIRECT_ROUTE 1 #endif +// The Model L choice in the launcher (CMake option WRONGGPU_MODEL_L, default OFF: on only in a release whose front end +// and runtime run Model L). OFF: no model setting anywhere (profile, `set`, `get`, the window); `set model=L` is +// refused by name. Converting Model L's data (`model convert --preset=L`) does not depend on it. +#ifndef WRONGGPU_MODEL_L +#define WRONGGPU_MODEL_L 0 +#endif // UI policy only. Silent installations keep their existing explicit command-line contract. namespace wg_wizard { diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index f58e6f66..77d8d405 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -97,6 +97,22 @@ int main() { require(!SelectPreset(lc, L"K", err) && err.find(L"M or L") != wstring::npos, "K is not a model of a build without Preset K"); #endif } +#if !WRONGGPU_MODEL_L + // ---- a build without the Model L choice (the default): no model setting anywhere; model=L refused by name ----------- + { + Profile mp = DefaultProfile(); + wstring mwhy; + require(!FindSetting("model") && !SetSetting(mp, "model", "L", &mwhy) && mwhy == kNoModelChoice, + "no Model L choice in this build: set model=L is refused by name"); + const string lfile = "[fsr]\r\nruntime_options = timing_log=1;model=L\r\n"; + string lout; + require(RenderWronggpuIni(mp, lfile, lout, &mwhy) && lout == lfile && ProfileText(mp).find("model=") == string::npos, + "no Model L choice: a model item in wronggpu.ini is left as it is, profile.ini has no model line"); + const string slotIni = "[WrongGPU]\r\nUpscalerIndex=1\r\n"; + RenderOptiIni(mp, slotIni, lout); + require(lout == slotIni, "no Model L choice: OptiScaler's UpscalerIndex is left as it is"); + } +#endif // ---- validation ----------------------------------------------------------------------------------------- string n; wstring why; const SettingDef* exec = FindSetting("executor"); diff --git a/clean/installer/tests/model_choice_tests.cpp b/clean/installer/tests/model_choice_tests.cpp new file mode 100644 index 00000000..612a32cd --- /dev/null +++ b/clean/installer/tests/model_choice_tests.cpp @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: MIT +// The Model L choice of the launcher (#89; profile.cpp built with WRONGGPU_MODEL_L on, whatever the launcher build's +// switch): the model setting, profile.ini, wronggpu.ini's model item and the OptiScaler entry OptiScaler starts with +// (UpscalerIndex). Model M changes nothing in either file, byte for byte. Written for this project. Run by ctest +// ("model-choice"). +#include +#include + +#include "wg_core/profile.h" + +using namespace wg; + +namespace { +int checks = 0; +void require(bool ok, const char* what) { + if (!ok) throw std::runtime_error(what); + ++checks; +} +Profile With(const char* model) { + Profile p = DefaultProfile(); + wstring why; + if (!SetSetting(p, "model", model, &why)) throw std::runtime_error("test setup: model"); + return p; +} +string Wini(const Profile& p, const string& in) { + string out; + wstring why; + if (!RenderWronggpuIni(p, in, out, &why)) throw std::runtime_error("test setup: render"); + return out; +} +string Oini(const Profile& p, const string& in, std::vector* notes = nullptr) { + string out; + RenderOptiIni(p, in, out, notes); + return out; +} +} // namespace + +int main() { + try { + // ---- the setting --------------------------------------------------------------------------------------------- + const SettingDef* d = FindSetting("model"); + require(d && d->layer == Layer::Model && string(d->def) == "m", "the model setting: Model M by default"); + Profile p = DefaultProfile(); + wstring why; + require(SetSetting(p, "model", "L", &why) && p.get("model") == "l", "model=L accepted (either case)"); + require(!SetSetting(p, "model", "K", &why) && why.find(L"allowed: m, l") != wstring::npos, "model=K is not a choice of the launcher"); + require(!SetSetting(p, "model", "Q", &why) && p.get("model") == "l", "a bad value is refused; the choice stays"); + + // ---- profile.ini: Model M as before the choice existed; L written and read back --------------------------------- + require(ProfileText(DefaultProfile()).find("model=") == string::npos, "profile.ini of a Model M game: no model line (as before)"); + const string lt = ProfileText(With("l")); + require(lt.find("model=l\r\n") != string::npos, "profile.ini of a Model L game: model=l"); + + // ---- wronggpu.ini -------------------------------------------------------------------------------------------- + const string fresh = "# WrongGPU settings\r\n[fsr]\r\nupscaler = network\r\nruntime_dll = wronggpu_runtime.dll\r\nruntime_options = model=M ; the model\r\n"; + require(Wini(DefaultProfile(), fresh) == fresh, "Model M: the installer's wronggpu.ini unchanged, byte for byte"); + const string withK = "[fsr]\r\nruntime_options = model=K\r\n"; + require(Wini(DefaultProfile(), withK) == withK, "Model M: Model K's item of a build with it stays as it is"); + const string toL = Wini(With("l"), fresh); + require(toL.find("runtime_options=model=L") != string::npos && toL.find("model=M") == string::npos && + toL.find("upscaler = network") != string::npos && toL.find("# WrongGPU settings") != string::npos, + "Model L: the model item is model=L; the other lines stay"); + require(Wini(With("l"), toL) == toL, "Model L again: unchanged (the line is rewritten only when its items change)"); + // (timing_log: an item the launcher does not manage, kept where it is) + const string mixed = "[fsr]\r\nruntime_options = model=M;timing_log=1;model=K\r\n"; + const string mixedL = Wini(With("l"), mixed); + require(mixedL.find("runtime_options=timing_log=1;model=L\r\n") != string::npos, "Model L: every model item out, model=L last (the last one wins)"); + const string backM = Wini(DefaultProfile(), "[fsr]\r\nruntime_options = timing_log=1;model=L\r\n"); + require(backM.find("runtime_options=timing_log=1;model=M\r\n") != string::npos, "back to Model M: Model L's item becomes model=M"); + require(EffectiveSettings(toL, "")["model"] == "l" && EffectiveSettings(fresh, "")["model"] == "m" && EffectiveSettings(withK, "")["model"] == "m", + "the file's model: L from its last model item, M otherwise"); + require(EffectiveSettings("[fsr]\r\nruntime_options = model=L;model=M\r\n", "")["model"] == "m", "the file's model: the last model item counts"); + + // ---- OptiScaler.ini: the entry OptiScaler starts with ----------------------------------------------------------- + const string L = kModelLEntryIndex; + const string slot = "[WrongGPU]\r\nUpscalerIndex=0\r\n[FSR]\r\nUpscalerIndex=0\r\n[Menu]\r\nShowFps=auto\r\n"; + require(Oini(DefaultProfile(), slot) == slot, "Model M: OptiScaler.ini unchanged, byte for byte"); + const string slotL = Oini(With("l"), slot); + require(slotL.find("[WrongGPU]\r\nUpscalerIndex=" + L + "\r\n") != string::npos && slotL.find("[FSR]\r\nUpscalerIndex=0\r\n") != string::npos, + "Model L, OptiScaler 10's slot: [WrongGPU] UpscalerIndex names Model L's entry; AMD's [FSR] entry is left to OptiScaler"); + require(Oini(With("l"), slotL) == slotL, "Model L again: unchanged"); + require(Oini(DefaultProfile(), slotL) == slot, "back to Model M: [WrongGPU] UpscalerIndex=0 again, the rest as it was"); + const string other = "[WrongGPU]\r\nUpscalerIndex=7\r\n"; + require(Oini(DefaultProfile(), other) == other, "Model M: another entry the player chose in OptiScaler's menu stays"); + const string fsr = "[FSR]\r\nUpscalerIndex=0\r\n"; + require(Oini(With("l"), fsr) == "[FSR]\r\nUpscalerIndex=" + L + "\r\n", "Model L, WrongGPU's FFX DLL as OptiScaler's FSR: [FSR] UpscalerIndex"); + std::vector notes; + const string none = "[Menu]\r\nShowFps=auto\r\n"; + require(Oini(With("l"), none, ¬es) == none && notes.size() == 1 && notes[0].find(L"no UpscalerIndex key") != wstring::npos, + "Model L without an UpscalerIndex key: nothing written, the player is told to choose it in OptiScaler's menu"); + Profile fps = With("l"); + SetSetting(fps, "fps_overlay", "on", &why); + require(Oini(fps, slot).find("ShowFps=true") != string::npos && Oini(fps, slot).find("UpscalerIndex=" + L) != string::npos, + "the FPS overlay setting still applies with the model"); + } catch (const std::exception& e) { + std::cerr << "model-choice FAILED after " << checks << " checks: " << e.what() << std::endl; + return 1; + } + std::cout << "model-choice: " << checks << " checks passed" << std::endl; + return 0; +} diff --git a/clean/installer/tests/run_model_l_tests.py b/clean/installer/tests/run_model_l_tests.py index 980d9b32..5871717e 100644 --- a/clean/installer/tests/run_model_l_tests.py +++ b/clean/installer/tests/run_model_l_tests.py @@ -203,23 +203,132 @@ def test_conversion(t, ref): rc == 0 and r.m_files().get("model.wgcm") == m_before.get("model.wgcm") and m_before.get("model.wgcm"), (rc, r.j)) +def upscaler_index(text): + """OptiScaler.ini's UpscalerIndex WrongGPU manages: [WrongGPU] (OptiScaler 10's slot) when there, else [FSR].""" + sec, found = None, {} + for line in text.replace("\r", "").split("\n"): + s = line.strip() + if s.startswith("["): + sec = s.strip("[]").lower() + elif s.lower().startswith("upscalerindex") and "=" in s: + found[sec] = s.split("=", 1)[1].strip() + return found.get("wronggpu", found.get("fsr")) + + +def recorded_hash(b, name): + """The hash the install record holds for a recorded file (its copy entry: action existed orig inst rel).""" + for line in read(os.path.join(b, "wronggpu-setup", "install.record")).decode("utf-8", "replace").replace("\r", "").split("\n"): + f = line.split("\t") + if len(f) == 5 and f[0] == "copy" and f[4].lower() == name.lower(): + return f[3].lower() + return None + + +def test_choice(t): + """The launcher's Model L choice (a build with WRONGGPU_MODEL_L on and the test map): set model=L/M on an installed + game. L only with Model L's data on this PC; it writes wronggpu.ini's model item and OptiScaler's UpscalerIndex, the + record's hashes follow (the file-ownership rule); M puts both files back byte for byte; uninstall restores the game.""" + print("\n[3] the model choice: set model=L / model=M (a build with the choice on)") + import run_launcher_tests as rl # (its game and OptiScaler fixtures: names and synthetic bytes only) + t.model = m_case() # rl.game() writes t.model.file as the game's DLSS file (this hides T.model, the path helper) + root, b, exe = rl.game(t, "Choice Game", validated=True) + before = suite.snapshot(root) + opti = rl.opti_package(t) + rc = t.run("install", exe, "--opti=" + opti, "--force") + t.check("install: exit 0", rc == 0, (rc, t.j.get("message"), t.stdout[-400:])) + if rc != 0: + return + wini, oini = os.path.join(b, "wronggpu.ini"), os.path.join(b, "OptiScaler.ini") + m_w, m_o = read(wini), read(oini) + rc = t.run("get", exe, "model") + t.check("get model: m (Model M, the default)", rc == 0 and t.j.get("settings", {}).get("model", {}).get("profile") == "m", t.j.get("settings")) + t.check("profile.ini of the Model M game: no model line", b"model=" not in read(os.path.join(b, "wronggpu-setup", "profile.ini"))) + rc = t.run("set", exe, "model=L") + t.check("set model=L without Model L's data: exit 5, refused by name, nothing changed", + rc == 5 and "Model L can't be chosen" in t.j.get("message", "") + t.j.get("error", "") and read(wini) == m_w and read(oini) == m_o, + (rc, t.j.get("message"), t.j.get("error"))) + lsrc = os.path.join(t.work, "l-source", "nvngx_dlss.dll") + write(lsrc, l_case().file) + rc = t.run("model", "convert", "--preset=L", "--model=" + lsrc) + t.check("Model L's data converted (model convert --preset=L)", rc == 0, (rc, t.j)) + rc = t.run("set", exe, "model=L") + w = read(wini).decode("utf-8", "replace") + t.check("set model=L: exit 0; wronggpu.ini's last model item is model=L", rc == 0 and suite_options_model(w) == "L", (rc, t.j.get("message"), w)) + t.check("...OptiScaler's UpscalerIndex names Model L's entry (1: after Model M in a build without Preset K)", + upscaler_index(read(oini).decode("utf-8", "replace")) == "1", read(oini).decode("utf-8", "replace")) + t.check("...the record's hashes follow both files (the file-ownership rule: they are WrongGPU's writes)", + recorded_hash(b, "wronggpu.ini") == hashlib.sha256(read(wini)).hexdigest() and recorded_hash(b, "OptiScaler.ini") == hashlib.sha256(read(oini)).hexdigest(), + (recorded_hash(b, "wronggpu.ini"), recorded_hash(b, "OptiScaler.ini"))) + t.check("...profile.ini says model=l", b"model=l\r\n" in read(os.path.join(b, "wronggpu-setup", "profile.ini"))) + rc = t.run("set", exe, "model=M") + t.check("set model=M: wronggpu.ini and OptiScaler.ini back byte for byte as the install wrote them", + rc == 0 and read(wini) == m_w and read(oini) == m_o, (rc, read(wini)[-200:], read(oini)[-200:])) + t.check("...profile.ini has no model line again", b"model=" not in read(os.path.join(b, "wronggpu-setup", "profile.ini"))) + # a game saved on L whose data goes away: a repair keeps the player's choice, the files say Model M with a warning + rc = t.run("set", exe, "model=L") + os.remove(os.path.join(t.lad, "WrongGPU", "model", "L", "model.wgcm")) # (t.model is the case here, not the path helper) + rc = t.run("repair", exe, "--opti=" + opti, "--force") + msgs = " ".join(t.j.get("warnings", []) + t.j.get("notes", [])) + t.check("repair of a game set to L without Model L's data: exit 0, the files say Model M, the player is told how to convert it", + rc == 0 and suite_options_model(read(wini).decode("utf-8", "replace")) == "M" and "Model L's data on this PC is not ready" in msgs and + "model convert --preset=L" in msgs, (rc, t.j.get("message"), msgs[:600])) + t.check("...the choice stays in profile.ini (model=l)", b"model=l\r\n" in read(os.path.join(b, "wronggpu-setup", "profile.ini"))) + rc = t.run("uninstall", exe) + t.check("uninstall: the game folder byte for byte as before the install", rc == 0 and suite.snapshot(root) == before, (rc, suite.diff(before, suite.snapshot(root)))) + + +def test_no_choice(t): + """A build without the choice (the default): model=L refused by name; nothing changes.""" + print("\n[4] a build without the model choice (the default)") + import run_launcher_tests as rl + t.model = m_case() + root, b, exe = rl.game(t, "No Choice Game", validated=True) + rc = t.run("install", exe, "--opti=" + rl.opti_package(t), "--force") + t.check("install: exit 0", rc == 0, (rc, t.j.get("message"))) + if rc != 0: + return + w, o = read(os.path.join(b, "wronggpu.ini")), read(os.path.join(b, "OptiScaler.ini")) + rc = t.run("set", exe, "model=L") + t.check("set model=L: a bad command line (exit 10), Model L named, nothing changed", + rc == 10 and t.j.get("error", "").startswith("Model L isn't part of this build of WrongGPU") and + read(os.path.join(b, "wronggpu.ini")) == w and read(os.path.join(b, "OptiScaler.ini")) == o, (rc, t.j)) + rc = t.run("get", exe) + t.check("get: no model setting listed", rc == 0 and "model" not in t.j.get("settings", {}), list(t.j.get("settings", {}))) + t.run("uninstall", exe) + + +def suite_options_model(text): + """The last model item of wronggpu.ini's runtime_options ("M", "L", ... or None).""" + model = None + for line in text.replace("\r", "").split("\n"): + s = line.strip() + if s.lower().startswith("runtime_options") and "=" in s: + for item in s.split("=", 1)[1].split(";"): + k, _, v = item.strip().partition("=") + if k.strip().lower() == "model": + model = v.strip().split()[0] if v.strip() else "" + return model + + def main(): ap = argparse.ArgumentParser() ap.add_argument("--write-test-map", help="write the test map (the shipped preset-L layout, our own digests) and stop") ap.add_argument("--launcher", help="WrongGPU.exe built with the shipped preset-L map") ap.add_argument("--launcher-synth", help="WrongGPU.exe built with --write-test-map's map (-DWRONGGPU_MAP_L=)") ap.add_argument("--reference-launcher", help="WrongGPU.exe of the base branch (same payload and test map)") + ap.add_argument("--launcher-choice", help="WrongGPU.exe built with -DWRONGGPU_MODEL_L=ON and the test map (the model choice)") ap.add_argument("--work", default=os.path.join(HERE, "..", "build-tests", "model-l")) a = ap.parse_args() if a.write_test_map: write(a.write_test_map, map_bytes(l_case())) print("test map: " + a.write_test_map) return 0 - if not a.launcher and not a.launcher_synth: - ap.error("--launcher or --launcher-synth is needed") + if not a.launcher and not a.launcher_synth and not a.launcher_choice: + ap.error("--launcher, --launcher-synth or --launcher-choice is needed") work = os.path.abspath(a.work) passed, failures = 0, [] - for exe, part, fn in ((a.launcher, "shipped", test_shipped_map), (a.launcher_synth, "synth", lambda t: test_conversion(t, a.reference_launcher))): + for exe, part, fn in ((a.launcher, "shipped", test_shipped_map), (a.launcher_synth, "synth", lambda t: test_conversion(t, a.reference_launcher)), + (a.launcher_choice, "choice", test_choice), (a.launcher_synth, "no-choice", test_no_choice)): if not exe: print("\n(%s: no launcher given, skipped)" % part) continue