Play your Steam library's Windows games on a jailbroken PS5.
C++
Show why a game setting value was refused
Leonardo Lobatoc34ec3af119b
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex bcc8e8d..033859a 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -8141,6 +8141,8 @@ void Simulation::start_editor(std::string purpose, std::string value, bool secreconst auto opener = state_.navigation.focus_key;editing_setting_id_.clear();editing_append_ = false;+ // A refusal belongs to the editor it was given in.+ std::erase_if(state_.notices, [](const Notice& notice) { return notice.id == "setting-validation"; });state_.editor = {};state_.editor.active = true;state_.editor.secret = secret;@@ -8328,8 +8330,9 @@ void Simulation::commit_editor() {const auto value = trimmed(state_.editor.value);const auto parsed = value.empty() ? std::optional<std::uint32_t>{0} : rt::ParseSteamAppId(value);if (!parsed || (!value.empty() && std::to_string(*parsed) != value)) {- state_.notices.push_back({"setting-validation", "Steam app ID: use the number in the game's Steam store address",- "", true, 0, true});+ std::erase_if(state_.notices, [](const Notice& notice) { return notice.id == "setting-validation"; });+ state_.notices.push_back({"setting-validation", "Steam app ID", "", true, 0, true,+ "Use the number in the game's Steam store address."});return;}std::erase_if(state_.notices, [](const Notice& notice) { return notice.id == "setting-validation"; });@@ -8357,7 +8360,12 @@ void Simulation::commit_editor() {}std::string reason;if (!value.empty() && !rt::ValidateSettingValue(RecipeFor(state_.navigation.selected_game_id), editing_setting_id_, value, &reason)) {- state_.notices.push_back({"setting-validation", state_.editor.purpose + ": " + reason, "", true, 0, true});+ // The setting on the first line, the whole reason below it (the reason can be long: a refused+ // variable also lists the accepted names).+ if (!reason.empty() && reason.front() >= 'a' && reason.front() <= 'z') reason.front() = static_cast<char>(reason.front() - 'a' + 'A');+ if (!reason.empty() && reason.back() != '.') reason += '.';+ std::erase_if(state_.notices, [](const Notice& notice) { return notice.id == "setting-validation"; });+ state_.notices.push_back({"setting-validation", state_.editor.purpose, "", true, 0, true, reason});return;}state_.notices.erase(std::remove_if(state_.notices.begin(), state_.notices.end(),@@ -8430,6 +8438,7 @@ void Simulation::cancel() {state_.editor.active = false;state_.editor.revealed = false;state_.navigation.focus_key = state_.editor.opener_focus_key;+ std::erase_if(state_.notices, [](const Notice& notice) { return notice.id == "setting-validation"; });return;}// An applied search is undone before Circle leaves the Library.diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cppindex 6f73699..66d4ef5 100644--- a/src/homebrew/view.cpp+++ b/src/homebrew/view.cpp@@ -3497,13 +3497,24 @@ class Render::Impl{if (!notice.persistent)continue;+ // The message on one line; a detail (why a value was refused) wraps below it, so the+ // reason is never cut.const float width = 560.0F;- scene_.rounded_rect({kWidth - kSafeX - width, y, width, 54.0F}, 8.0F,- kAmber.with_alpha(0.16F));- scene_.circle(kWidth - kSafeX - width + 25.0F, y + 27.0F, 6.0F, kAmber);+ const float left = kWidth - kSafeX - width;+ constexpr int kDetailLines = 4;+ constexpr float kDetailLine = 28.0F;+ const std::size_t wrapped =+ notice.detail.empty() ? 0 : fonts_.regular.font->wrap(notice.detail, 20.0F, width - 64.0F).size();+ const float detail_height = static_cast<float>(std::min<std::size_t>(wrapped, kDetailLines)) * kDetailLine;+ const float height = 54.0F + (detail_height > 0.0F ? detail_height + 4.0F : 0.0F);+ scene_.rounded_rect({left, y, width, height}, 8.0F, kAmber.with_alpha(0.16F));+ scene_.circle(left + 25.0F, y + 27.0F, 6.0F, kAmber);ui::text(scene_, fonts_.regular, fit(fonts_.regular, notice.message, 21.0F, width - 64.0F),- kWidth - kSafeX - width + 44.0F, y + 35.0F, 21.0F, kText);- y += 64.0F;+ left + 44.0F, y + 35.0F, 21.0F, kText);+ if (wrapped > 0)+ ui::paragraph(scene_, fonts_.regular, notice.detail, left + 44.0F, y + 35.0F + kDetailLine + 2.0F,+ 20.0F, width - 64.0F, kDetailLine, kSecondary, kDetailLines);+ y += height + 10.0F;}}@@ -3698,6 +3709,11 @@ class Render::Imploverlay_.rounded_rect({std::min(caret_x, field.x + field.w - 24.0F), field.y + 18.0F,2.0F, field.h - 36.0F},1.0F, kAccent);+ // Why the value was refused, under the field: the corner notice is behind this panel.+ for (const Notice ¬ice : state.notices)+ if (notice.id == "setting-validation" && !notice.detail.empty())+ ui::paragraph(overlay_, fonts_.regular, notice.detail, field.x, field.y + field.h + 40.0F, 24.0F,+ field.w, 34.0F, kAmber, 3);keyboard_.style.reduced_motion = state.reduced_motion;const int layouts = !state.editor.secret ? 0 : state.editor.revealed ? 2 : 1;if (layouts != keyboard_layouts_)diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cppindex 083df71..eae565e 100644--- a/src/runtime/game_settings.cpp+++ b/src/runtime/game_settings.cpp@@ -285,7 +285,8 @@ std::vector<SettingDefinition> BuildCatalogue() {// Advanced.{auto environment = Text("environment", "Environment variables",- "Extra variables for the game, separated by ';', like WINE_CPU_TOPOLOGY=4:0,1,2,3.",+ std::string("Extra variables for the game, separated by ';', like WINE_CPU_TOPOLOGY=4:0,1,2,3. ") ++ kEnvironmentNamesHint,"[environment]", G::kAdvanced);environment.phase = 2;list.push_back(std::move(environment));@@ -741,7 +742,7 @@ bool ValidateSettingValue(const GameRecipe& recipe, std::string_view id, std::stwhile (!item.empty() && item.front() == ' ') item.remove_prefix(1);if (!IsProsperoEnvironmentEntry(name, item) && !IsProsperoDebugEnvEntry(name, item) &&!IsBottleEnvironmentEntry(name, item))- return fail(std::string(name) + " is not an allowed variable");+ return fail(std::string(name) + " is not an allowed variable. " + kEnvironmentNamesHint);if (!names.insert(std::string(name)).second) return fail(std::string(name) + " appears twice");if (++count > kProsperoMaxEnvironmentEntries) return fail("at most 8 variables");}diff --git a/src/runtime/game_settings.h b/src/runtime/game_settings.hindex 06e7143..add2ca5 100644--- a/src/runtime/game_settings.h+++ b/src/runtime/game_settings.h@@ -312,6 +312,11 @@ std::string SettingChoiceUnavailable(const EffectiveSettings& settings, std::str// be saved now; until then the row applies the Playden default (EffectiveValue::after_update).bool SettingChoiceWaitsForUpdate(const EffectiveSettings& settings, std::string_view id, std::string_view value);+// The variables Environment variables accepts (IsProsperoEnvironmentEntry, IsProsperoDebugEnvEntry and+// IsBottleEnvironmentEntry), as the setting's description and a refusal tell the player.+inline constexpr char kEnvironmentNamesHint[] =+ "Allowed names start with DXVK_, MESA_, RADV_, SDL_, VK_, VKD3D_, ZINK_, GALLIUM_ or PW_, or are WINE_CPU_TOPOLOGY.";+// Checks one player value for one setting; used by the UI before saving an override.bool ValidateSettingValue(const GameRecipe& recipe, std::string_view id, std::string_view value, std::string* reason);diff --git a/tests/game_settings_test.cpp b/tests/game_settings_test.cppindex 0d7cf4a..eeffb98 100644--- a/tests/game_settings_test.cpp+++ b/tests/game_settings_test.cpp@@ -1141,6 +1141,15 @@ int main(int argc, char** argv) {CHECK(!ValidateSettingValue(hl2, "environment", "DXVK_HUD=full", &reason));CHECK(!ValidateSettingValue(hl2, "environment", "DXVK_A=1;DXVK_A=2", &reason));CHECK(!ValidateSettingValue(hl2, "environment", "DXVK_A", &reason));+ // A refused name says which names are allowed, and every name the hint lists is (#480).+ CHECK(!ValidateSettingValue(hl2, "environment", "PROTON_LOG=1", &reason) &&+ reason == std::string("PROTON_LOG is not an allowed variable. ") + kEnvironmentNamesHint);+ for (const char* prefix : {"DXVK_", "MESA_", "RADV_", "SDL_", "VK_", "ZINK_", "GALLIUM_", "PW_"}) {+ CHECK(std::string_view(kEnvironmentNamesHint).find(std::string(prefix) + ",") != std::string_view::npos ||+ std::string_view(kEnvironmentNamesHint).find(std::string(prefix) + " ") != std::string_view::npos);+ CHECK(ValidateSettingValue(hl2, "environment", std::string(prefix) + "PLAYDEN_TEST=1", &reason));+ }+ CHECK(ValidateSettingValue(hl2, "environment", "VKD3D_CONFIG=dxr;WINE_CPU_TOPOLOGY=4:0,1,2,3", &reason));// Registry settings: Windows version per executable and text scale, edited in user.reg.KitCapabilities registry_kit;diff --git a/tests/homebrew_simulation_test.cpp b/tests/homebrew_simulation_test.cppindex dc71d6c..3bb7453 100644--- a/tests/homebrew_simulation_test.cpp+++ b/tests/homebrew_simulation_test.cpp@@ -1008,6 +1008,55 @@ void t52_recipe_values_in_game_settings(const std::filesystem::path& fixtures, cactivate(simulation, "value-reset");check(!overrides().count("dll_overrides"), "T52 library overrides reset");+ // A refused value keeps the editor open with a notice: the setting first, then the whole reason, which+ // names the variables Environment variables accepts (#480). The row says which ones too.+ {+ playden::runtime::KitCapabilities kit;+ kit.environment = true;+ simulation.SetKitCapabilities(kit);+ }+ check(find_row(simulation, "setting-environment") != nullptr, "T52 Environment variables is listed");+ check(find_row(simulation, "setting-environment")->subtitle.find("DXVK_") != std::string::npos,+ "T52 Environment variables names the variables it accepts");+ activate(simulation, "setting-environment");+ check(simulation.state().editor.active, "T52 Environment variables opens the keyboard");+ simulation.text("PROTON_DISABLE_LSTEAMCLIENT=1");+ simulation.action("done");+ {+ const auto refused = std::find_if(simulation.state().notices.begin(), simulation.state().notices.end(),+ [](const auto& notice) { return notice.id == "setting-validation"; });+ check(simulation.state().editor.active && refused != simulation.state().notices.end() && refused->persistent,+ "T52 a refused variable keeps the editor open with a notice");+ check(refused != simulation.state().notices.end() && refused->message == "Environment variables" &&+ refused->detail.rfind("PROTON_DISABLE_LSTEAMCLIENT is not an allowed variable.", 0) == 0 &&+ refused->detail.find("DXVK_") != std::string::npos &&+ refused->detail.find("WINE_CPU_TOPOLOGY") != std::string::npos,+ "T52 the notice gives the whole reason and the accepted names");+ }+ // Cancelled, the refusal goes with the editor and does not show in the next one.+ simulation.action("circle");+ check(!simulation.state().editor.active &&+ std::none_of(simulation.state().notices.begin(), simulation.state().notices.end(),+ [](const auto& notice) { return notice.id == "setting-validation"; }),+ "T52 a cancelled editor takes its refusal with it");+ activate(simulation, "setting-environment");+ simulation.action("triangle"); // clears the editor+ simulation.text("PROTON_LOG=1");+ simulation.action("done");+ check(simulation.state().editor.active, "T52 refused again");+ simulation.action("triangle"); // clears the editor+ simulation.text("DXVK_ASYNC=1");+ simulation.action("done");+ check(overrides().at("environment") == "DXVK_ASYNC=1" &&+ std::none_of(simulation.state().notices.begin(), simulation.state().notices.end(),+ [](const auto& notice) { return notice.id == "setting-validation"; }),+ "T52 an accepted variable saves and clears the notice");+ activate(simulation, "setting-environment");+ simulation.action("triangle");+ simulation.action("done");+ check(!overrides().count("environment") || overrides().at("environment").empty(), "T52 Environment variables clear");+ simulation.SetKitCapabilities({});+// Locked rows: Change anyway, then reset to the recipe.activate(simulation, "setting-graphics");activate(simulation, "unlock-setting");