Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions clean/fsr/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,30 @@ std::string Config::BackendOptions() const {
return extra.empty() ? std::string(buffer) : std::string(buffer) + ";" + extra;
}

void ApplyStateSettings(Config& c, const std::vector<std::pair<std::string, std::string>>& kv, std::string* notes) {
auto note = [&](const std::string& s) { if (notes) *notes += s + "\n"; };
std::string items;
for (const auto& p : kv) {
const std::string& key = p.first;
const std::string lv = Lower(p.second);
if (key == "upscaler") {
if (lv == "network") c.upscaler = UpscalerChoice::Network;
else if (lv == "amd") c.upscaler = UpscalerChoice::Amd;
else if (lv == "standin" || lv == "stand-in") c.upscaler = UpscalerChoice::StandIn;
else { note("settings.ini: bad value \"" + p.second + "\" for upscaler (wronggpu.ini's kept)"); continue; }
note("settings.ini: upscaler = " + lv + " (over wronggpu.ini)");
} else if (key.rfind("rr_", 0) == 0 || key == "model") {
continue; // the RR plugin's keys and the model choice record's: not the front end's
} else if (IsRuntimeOptionKey(key)) {
items += (items.empty() ? "" : ";") + key + "=" + p.second;
note("settings.ini: " + key + " = " + p.second + " (over wronggpu.ini)");
} else {
note("settings.ini: unknown key \"" + key + "\" (ignored)");
}
}
if (!items.empty()) c.runtimeOptions = NormalizeOptions(c.runtimeOptions + ";" + items);
}

std::string OptionValue(const std::string& options, const char* key, bool* found) {
std::string value;
bool any = false;
Expand Down
9 changes: 9 additions & 0 deletions clean/fsr/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdint>
#include <functional>
#include <string>
#include <utility>
#include <vector>

#include "model_k.h"
Expand Down Expand Up @@ -129,6 +130,14 @@ struct Config {
// (runtime_keys.h, e.g. "network = fused") is appended to runtime_options as "network=fused", with a warning.
Config ParseConfig(const std::string& text, std::string* warnings);

// #219 (0.6.5): the settings chosen in the WrongGPU launcher are in the game's state folder, <folder of wronggpu.ini>\
// wronggpu-setup\settings.ini (clean/wgshared/include/wg_state.h), and take precedence over wronggpu.ini (the install's
// defaults, the player's to edit; the launcher never rewrites it). Applied over a parsed Config: `upscaler` (network, amd,
// standin) and every runtime option key (runtime_keys.h) as an item appended to runtime_options (the runtime takes a key's
// last value). The RR plugin's keys (rr_*) and `model` (the model choice record's) are not the front end's and are skipped;
// any other key is reported in *notes and ignored. *notes gets one line per applied key.
void ApplyStateSettings(Config& c, const std::vector<std::pair<std::string, std::string>>& kv, std::string* notes);

// Windows virtual-key code of an overlay_key value ("insert", "f9", "0x2d", ...); 0 when not recognised.
int OverlayKeyCode(const std::string& name);

Expand Down
15 changes: 15 additions & 0 deletions clean/fsr/src/win_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "amd_provider.h"
#include "settings_bridge.h"
#include "wg_settings_io.h"
#include "../../wgshared/include/wg_state.h" // #219: the game's state folder (settings.ini)
#include "standin_d3d12.h"
#include "provider_label.h"

Expand Down Expand Up @@ -462,6 +463,20 @@ wgfsr::Config ReadSettings(const std::string& tag) {
}
std::string warnings;
wgfsr::Config config = wgfsr::ParseConfig(text, &warnings);
// #219: the settings chosen in the launcher (the game's state folder beside wronggpu.ini) over wronggpu.ini's defaults
{
const std::wstring iniDir = path.substr(0, path.find_last_of(L"\\/"));
const wgstate::Settings st = wgstate::ReadSettings(iniDir);
if (st.corrupt || !st.why.empty())
L().WriteLine(tag + "settings: " + Narrow(wgstate::SettingsPathOf(iniDir)) + " not used: " + st.why + " (wronggpu.ini's values apply)");
std::string notes;
wgfsr::ApplyStateSettings(config, st.kv, &notes);
for (size_t a = 0; a < notes.size();) {
const size_t e = notes.find('\n', a);
L().WriteLine(tag + notes.substr(a, e - a));
a = e == std::string::npos ? notes.size() : e + 1;
}
}
// Registry options the front end reads (clean/wgshared; [wronggpu] keys, block and environment first): set there,
// they decide over the [fsr] keys of the same meaning.
{
Expand Down
24 changes: 24 additions & 0 deletions clean/fsr/tests/test_frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3472,6 +3472,29 @@ static void TestWithoutModelL() {
}
#endif

// #219: the launcher's settings in the game's state folder (settings.ini) over wronggpu.ini (config.h ApplyStateSettings)
static void TestStateSettings() {
std::string w;
Config c = ParseConfig("upscaler = amd\nruntime_options = executor=hip;sync=pipelined;output_filter=analytic\n", &w);
std::string notes;
ApplyStateSettings(c, {{"upscaler", "network"}, {"executor", "dx12"}, {"output_filter", "default"}, {"sparkle_guard", "off"},
{"rr_mode", "fast"}, {"model", "L"}, {"no_such_key", "1"}},
&notes);
CHECK(c.upscaler == UpscalerChoice::Network); // the state's upscaler decides
// the runtime takes a key's last value: the state's items come after wronggpu.ini's
CHECK(c.runtimeOptions == "executor=hip;sync=pipelined;output_filter=analytic;executor=dx12;output_filter=default;sparkle_guard=off");
CHECK(OptionValue(c.runtimeOptions, "sync", nullptr) == "pipelined"); // a key the state does not hold stays as the file has it
CHECK(c.runtimeOptions.find("rr_mode") == std::string::npos && c.runtimeOptions.find("model=") == std::string::npos); // not the front end's
CHECK(notes.find("unknown key \"no_such_key\"") != std::string::npos && notes.find("upscaler = network") != std::string::npos);
Config d = ParseConfig("upscaler = network\n", &w);
notes.clear();
ApplyStateSettings(d, {{"upscaler", "turbo"}}, &notes);
CHECK(d.upscaler == UpscalerChoice::Network && notes.find("bad value") != std::string::npos); // a bad value: the file's kept
Config e = ParseConfig("upscaler = amd\n", &w);
ApplyStateSettings(e, {}, nullptr);
CHECK(e.upscaler == UpscalerChoice::Amd && e.runtimeOptions.empty()); // no state: wronggpu.ini as it is
}

int main() {
TestCustomSlotFailedCreate();
TestCustomSlotFailureKeyHasSize();
Expand Down Expand Up @@ -3559,6 +3582,7 @@ int main() {
TestLogThinning();
TestHosted();
TestHostVersionHandling();
TestStateSettings();
if (const char* dump = std::getenv("WG_TEST_DUMP_LOG")) {
(void)dump;
for (const auto& line : g_log) std::printf("%s\n", line.c_str());
Expand Down
54 changes: 41 additions & 13 deletions clean/installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ payload file built with the front end) for every game and sets OptiScaler.ini `[
`Path=auto` (the section is added when the player's ini has none). On the OptiScaler builds the plugin recognises,
"WrongGPU" is then an entry of OptiScaler's main upscaler list and its default, and OptiScaler's FSR 3.X/4 entry is
AMD's upscaler; on any other build the plugin changes nothing and WrongGPU stays the first entry of the FFX box.
`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`.
`Dx12Upscaler=fsr31`, `FfxDx12SRPath` and `UpscalerIndex=0` stay as before. Uninstall removes the plugin and its folder
when the install made it, and puts the player's OptiScaler.ini back. The plugin's starting entry `wronggpu-asi.ini` (a
Preset K build writes it) is one of the install's recorded files (#219): an uninstall removes it while it is unchanged
and keeps it, listed, once the plugin's menu or the player changed it (an update keeps such a file as it is). The
plugin's log `wronggpu-asi.log` is not recorded and stays, listed. 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
Expand Down Expand Up @@ -245,8 +247,9 @@ With the defaults nothing of this section changes the installer.
- **What the launcher removes or overwrites: the file-ownership rule** (0.6.1; the restore, uninstall, repair, update, move
out of a wrong folder and the state-folder cleanup; `src/wg_core/record.h`). In the game's folders, a file
is deleted or overwritten only when its current bytes are WrongGPU's: the hash the install record says WrongGPU last
wrote there (every write of the launcher to `wronggpu.ini`, `OptiScaler.ini` and the RR plugin's settings updates that
hash). Nothing else proves it: not the file's name, not a file next to it, not an ini key, not "it is a log", not "the
wrote there (every write of the launcher to `OptiScaler.ini` updates that hash; `wronggpu.ini` and the RR plugin's
`WrongGPU\wronggpu.ini` are written once, by the install, and never rewritten after it: see the saved settings below).
Nothing else proves it: not the file's name, not a file next to it, not an ini key, not "it is a log", not "the
install created that path". A file that is not in the record is not touched, whatever its name (`wronggpu-*`,
`OptiScaler.log`, `fakenvapi.log`, ...).
- **Two policies, stated here on purpose.** Files in WrongGPU's FSR slot that identify as WrongGPU (the version
Expand All @@ -267,8 +270,15 @@ With the defaults nothing of this section changes the installer.
where a hash is known, its bytes are those. The backups the record lists go while they match the entry's hash; the
previous version's files that `previous.txt` lists go while they match the hashes it states (a changed one stays and
is listed); `owned-files.json` goes while it is byte for byte what WrongGPU makes of the record. The record,
`previous.txt`, `uninstall.exe`, `setup.log` and `profile.ini` carry no recorded hash and go by their fixed names (the one
place the rule is by name). The player's Engine.ini copy (`rr-config`) goes only through the Engine.ini revert. Any other
`previous.txt`, `uninstall.exe`, `setup.log` and `profile.ini` carry no recorded hash and go by their fixed names.
The saved settings `settings.ini` and `model-choice.ini` go only while their bytes carry WrongGPU's stamp: a last
line `; wronggpu-written <check>` whose check covers every byte before it, the file's own name and this install's id
(the record's `install-id`, kept by repair and update). WrongGPU stamps a state file it creates and keeps the stamp
only while nobody else changes the file. A file the player edited or made, a copy under another name (a temporary
file among them) or from another install stays and is listed. Repair and update keep them. A save never overwrites
a change made meanwhile: the file is held from the read to the move, and a change in the last moment refuses the save.
A failed install, repair or update takes back only what that run made (written down before each create); everything
else in the state folder stays and is listed. The player's Engine.ini copy (`rr-config`) goes only through the Engine.ini revert. Any other
file stays, the folder stays with it, and the result lists what was left. The same applies when an install is moved
out of a wrong folder. The shared folder `%LOCALAPPDATA%\WrongGPU` is not in a game's folder; see Uninstall.
- **A settings file in a build without Preset K.** The plugin's `wronggpu-asi.ini` is rewritten (its `selection=wronggpu-k`
Expand All @@ -284,6 +294,23 @@ With the defaults nothing of this section changes the installer.
any file); the game's FSR DLL, in the one step where WrongGPU's DLL is deleted and the game's file takes its name,
is held until deleted and the move that follows creates the name only if free; the install, repair and update steps
that write into the game folder and the Engine.ini edit that adds the line are not covered by this (tracked separately).
- **The saved settings** (#219; `clean/wgshared/include/wg_state.h`). Settings you change in the launcher or the in-game
menu are saved in `wronggpu-setup\settings.ini` and take precedence over `wronggpu.ini` (the FSR front end reads the
upscaler and its runtime option keys from there, the RR plugin `rr_*`). `wronggpu.ini` and `WrongGPU\wronggpu.ini`
keep the install's defaults and are the player's to edit; no launcher operation and no plugin rewrites them after the
install, so a save in the game never makes them look edited, and an uninstall after a save leaves nothing behind.
Every write of `settings.ini` takes the game's state lock (one named mutex per game folder, shared by the launcher,
the front end and the plugins) and replaces the file whole (`WriteAtomic`); a write that cannot take the lock or
cannot be made is reported, never silent (the launcher stops with "Settings not applied: ...", the RR menu logs
"not saved: ..."). An install from before #219 whose `WrongGPU\wronggpu.ini` differs from the record (an older
plugin's save or the player's edit) is the player's: its `rr_mode` and `rr_overlay` are copied into `settings.ini`
once and the file is kept.
- **Uninstall, repair and update refuse while WrongGPU is in use.** For the whole operation the launcher holds the
record's WrongGPU binaries (`.dll`, `.asi`) open for writing and deleting (`OperationGuard`); a binary the game has
loaded, or another program has open without sharing writes (antivirus, a backup tool), cannot be opened that way, so
the operation stops before anything changes: "Nothing was changed: WrongGPU's files are in use by the game or another
program (for example antivirus). Close the game and try again (<file>)." A binary the operation replaces or creates
is renamed in complete and held at once; the old one is deleted through its handle.
- **Roll back** holds every payload file it changes through one handle (as above), compares its bytes with the hash the
record says WrongGPU installed, keeps the current files for a later update by copying them out through those handles
into a new swap folder, and then overwrites through them. The earlier files are held and hashed too, all of them before
Expand Down Expand Up @@ -449,12 +476,13 @@ Basic tier: `wronggpu` (on | off: `[fsr] upscaler = network | amd`), `executor`
original), `sparkle_guard` (off | on | a rate in (0, 1)), `fps_overlay` (keep | on | off: OptiScaler's
`[Menu] ShowFps`, written only when that key exists in the game's OptiScaler.ini). On the game page Use WrongGPU is in view; Runs on, Output filter, Pre-exposure and Sparkle guard are under
"Advanced settings (4)", shown when one of them is off its default, unsaved or changed outside the launcher (`AdvancedWanted`). Every value is checked before
anything is written. `wronggpu.ini` gets only what differs from the defaults: the managed runtime items are removed
from `runtime_options` (and from lines of their own, which the front end appends) and the non-default ones appended
in a fixed order, one line without spaces; other items, comments, unknown keys and sections stay. A value in the
files that differs from both its default and the profile is an outside edit (Keep / Revert). After every install,
update and repair the profile is written into the files again; the record learns the new hashes of `wronggpu.ini`
and `OptiScaler.ini`, so an uninstall can still prove they are WrongGPU's.
anything is written. The front end's settings go into `wronggpu-setup\settings.ini` (#219): `upscaler` and every
managed runtime key, defaults too, so they decide over `wronggpu.ini`, which keeps the install's defaults and is not
rewritten (the front end puts the state's keys over the file's `runtime_options`, last value wins). The Model L/K
choice is not one of these keys (`model-choice.ini`). A value in the effective settings that differs from both its
default and the profile is an outside edit (Keep / Revert). After every install, update and repair the profile is
written again (`settings.ini`, `OptiScaler.ini`); the record learns the new hash of `OptiScaler.ini`, so an uninstall
can still prove it is WrongGPU's.

**Record v2** (`WRONGGPU-RECORD 2`, `src/wg_core/record.*`): the v1 lines plus `payload`, `proxy` and one `owner` line
per action (`wg`, `wg-optibundle`, `adopted`, `moved`); action lines keep their five fields, so a 0.5.x uninstaller
Expand Down
2 changes: 1 addition & 1 deletion clean/installer/src/app/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ int Verb(const wstring& verb, const Args& a, Output& o) {
if (res.code) return res.code;
}
string wini, oini;
ReadAll(Join(dir, L"wronggpu.ini"), wini);
wini = EffectiveWronggpuIni(dir); // (#219: the state folder over the file)
ReadAll(Join(dir, L"OptiScaler.ini"), oini);
auto eff = EffectiveSettings(wini, oini);
if (const RrFileState rs = ReadRrSettings(dir); rs.present) { // Ray Reconstruction: the RR plugin's settings file
Expand Down
2 changes: 1 addition & 1 deletion clean/installer/src/app/launcher_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ PageData ReadPageData(const GameEntry& e, const Profile& defaults) {
d.saved = e.hasRecord ? GameProfile(e.dir) : defaults;
d.opti = ReadOpti(e);
string wini, oini;
ReadAll(Join(e.dir, L"wronggpu.ini"), wini);
wini = EffectiveWronggpuIni(e.dir); // (#219: the state folder over the file)
ReadAll(Join(e.dir, L"OptiScaler.ini"), oini);
d.outside = e.hasRecord ? OutsideEdits(d.saved, wini, oini) : std::vector<OutsideEdit>{};
if (const RrConfigGame* rg = e.hasRecord ? RrConfigGameFor(e.exe) : nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion clean/installer/src/app/ui_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FirstRunChecks(HWND hwnd, const GlobalSettings& gs, const wstring& dll, boo
std::vector<wstring> pn;
if (!IsFile(ProfilePath(e.dir))) {
string wini, oini;
ReadAll(Join(e.dir, L"wronggpu.ini"), wini);
wini = EffectiveWronggpuIni(e.dir); // (#219: the state folder over the file)
ReadAll(Join(e.dir, L"OptiScaler.ini"), oini);
ImportProfile(wini, oini, &pn);
}
Expand Down
Loading
Loading