Browse Source

more fixes for enums

lizzie/crashes-qt-somesettings
lizzie 2 days ago
parent
commit
1edc77cb53
  1. 2
      src/common/settings_enums.h
  2. 9
      src/common/settings_setting.h
  3. 47
      src/frontend_common/config.cpp
  4. 15
      src/input_common/drivers/udp_client.cpp
  5. 8
      src/yuzu/game/game_list.cpp
  6. 2
      tools/README.md
  7. 11
      tools/fuzzsettings.cpp

2
src/common/settings_enums.h

@ -75,7 +75,7 @@ struct EnumMetadata {
#define PP_HEAD(A, ...) A #define PP_HEAD(A, ...) A
#define ENUM(NAME, ...) \ #define ENUM(NAME, ...) \
enum class NAME : u32 { __VA_ARGS__ }; \
enum class NAME : u32 { __VA_ARGS__, Count }; \
template<> inline std::vector<std::pair<std::string_view, NAME>> EnumMetadata<NAME>::Canonicalizations() { \ template<> inline std::vector<std::pair<std::string_view, NAME>> EnumMetadata<NAME>::Canonicalizations() { \
return {PAIR(NAME, __VA_ARGS__)}; \ return {PAIR(NAME, __VA_ARGS__)}; \
} \ } \

9
src/common/settings_setting.h

@ -11,6 +11,7 @@
#include <optional> #include <optional>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <type_traits>
#include <typeindex> #include <typeindex>
#include <typeinfo> #include <typeinfo>
#include <fmt/core.h> #include <fmt/core.h>
@ -371,7 +372,13 @@ public:
* @param val The new value * @param val The new value
*/ */
void SetValue(const Type& val) override final { void SetValue(const Type& val) override final {
Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val};
// Enums have a maximal range which they're allowed
Type temp{};
if constexpr (std::is_enum_v<Type>) {
temp = Type(std::clamp(std::underlying_type_t<Type>(val), std::underlying_type_t<Type>(0), std::underlying_type_t<Type>(Type::Count) - 1));
} else {
temp = ranged ? std::clamp(val, this->minimum, this->maximum) : val;
}
if (use_global) { if (use_global) {
std::swap(this->value, temp); std::swap(this->value, temp);
} else { } else {

47
src/frontend_common/config.cpp

@ -238,28 +238,22 @@ void Config::ReadControlValues() {
void Config::ReadMotionTouchValues() { void Config::ReadMotionTouchValues() {
Settings::values.touch_from_button_maps.clear(); Settings::values.touch_from_button_maps.clear();
int num_touch_from_button_maps = BeginArray(std::string("touch_from_button_maps")); int num_touch_from_button_maps = BeginArray(std::string("touch_from_button_maps"));
if (num_touch_from_button_maps > 0) { if (num_touch_from_button_maps > 0) {
for (int i = 0; i < num_touch_from_button_maps; ++i) { for (int i = 0; i < num_touch_from_button_maps; ++i) {
SetArrayIndex(i); SetArrayIndex(i);
Settings::TouchFromButtonMap map; Settings::TouchFromButtonMap map;
map.name = ReadStringSetting(std::string("name"), std::string("default")); map.name = ReadStringSetting(std::string("name"), std::string("default"));
int const num_touch_maps = BeginArray(std::string("entries")); int const num_touch_maps = BeginArray(std::string("entries"));
if (num_touch_maps > 0) {
map.buttons.reserve(num_touch_maps);
for (int j = 0; j < num_touch_maps; j++) {
SetArrayIndex(j);
std::string touch_mapping = ReadStringSetting(std::string("bind"));
map.buttons.emplace_back(std::move(touch_mapping));
}
map.buttons.resize(num_touch_maps);
for (int j = 0; j < num_touch_maps; j++) {
SetArrayIndex(j);
map.buttons[j] = ReadStringSetting(std::string("bind"));
} }
EndArray(); // entries EndArray(); // entries
Settings::values.touch_from_button_maps.emplace_back(std::move(map)); Settings::values.touch_from_button_maps.emplace_back(std::move(map));
} }
} else { } else {
Settings::values.touch_from_button_maps.emplace_back(
Settings::TouchFromButtonMap{"default", {}});
Settings::values.touch_from_button_maps.emplace_back(Settings::TouchFromButtonMap{"default", {}});
num_touch_from_button_maps = 1; num_touch_from_button_maps = 1;
} }
EndArray(); // touch_from_button_maps EndArray(); // touch_from_button_maps
@ -501,15 +495,12 @@ void Config::SaveMotionTouchValues() {
BeginArray(std::string("touch_from_button_maps")); BeginArray(std::string("touch_from_button_maps"));
for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) { for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) {
SetArrayIndex(int(p)); SetArrayIndex(int(p));
WriteStringSetting(std::string("name"), Settings::values.touch_from_button_maps[p].name,
std::make_optional(std::string("default")));
WriteStringSetting(std::string("name"), Settings::values.touch_from_button_maps[p].name, std::make_optional(std::string("default")));
BeginArray(std::string("entries")); BeginArray(std::string("entries"));
for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size(); for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size();
++q) { ++q) {
SetArrayIndex(int(q)); SetArrayIndex(int(q));
WriteStringSetting(std::string("bind"),
Settings::values.touch_from_button_maps[p].buttons[q]);
WriteStringSetting(std::string("bind"), Settings::values.touch_from_button_maps[p].buttons[q]);
} }
EndArray(); // entries EndArray(); // entries
} }
@ -638,8 +629,7 @@ void Config::SaveDisabledAddOnValues() {
BeginArray(std::string("disabled")); BeginArray(std::string("disabled"));
for (std::size_t j = 0; j < elem.second.size(); ++j) { for (std::size_t j = 0; j < elem.second.size(); ++j) {
SetArrayIndex(int(j)); SetArrayIndex(int(j));
WriteStringSetting(std::string("d"), elem.second[j],
std::make_optional(std::string("")));
WriteStringSetting(std::string("d"), elem.second[j], std::make_optional(std::string("")));
} }
EndArray(); // disabled EndArray(); // disabled
++i; ++i;
@ -733,21 +723,18 @@ s64 Config::ReadIntegerSetting(const std::string& key, const std::optional<s64>
std::string full_key = GetFullKey(key, false); std::string full_key = GetFullKey(key, false);
if (!default_value.has_value()) { if (!default_value.has_value()) {
try { try {
return std::stoll(
std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), "0")));
return std::stoll(std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), "0")));
} catch (...) { } catch (...) {
return 0; return 0;
} }
} }
s64 result = 0; s64 result = 0;
if (config->GetBoolValue(GetSection().c_str(),
std::string(full_key).append("\\default").c_str(), true)) {
if (config->GetBoolValue(GetSection().c_str(), std::string(full_key).append("\\default").c_str(), true)) {
result = default_value.value(); result = default_value.value();
} else { } else {
try { try {
result = std::stoll(std::string(config->GetValue(
GetSection().c_str(), full_key.c_str(), ToString(default_value.value()).c_str())));
result = std::stoll(std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), ToString(default_value.value()).c_str())));
} catch (...) { } catch (...) {
result = default_value.value(); result = default_value.value();
} }
@ -919,14 +906,12 @@ void Config::ReadSettingGeneric(Settings::BasicSetting* const setting) {
bool use_global = true; bool use_global = true;
if (setting->Switchable() && !global) { if (setting->Switchable() && !global) {
use_global =
ReadBooleanSetting(std::string(key).append("\\use_global"), std::make_optional(true));
use_global = ReadBooleanSetting(std::string(key).append("\\use_global"), std::make_optional(true));
setting->SetGlobal(use_global); setting->SetGlobal(use_global);
} }
if (global || !use_global) { if (global || !use_global) {
const bool is_default =
ReadBooleanSetting(std::string(key).append("\\default"), std::make_optional(true));
const bool is_default = ReadBooleanSetting(std::string(key).append("\\default"), std::make_optional(true));
if (!is_default) { if (!is_default) {
setting->LoadString(ReadStringSetting(key, default_value)); setting->LoadString(ReadStringSetting(key, default_value));
} else { } else {
@ -1051,8 +1036,8 @@ std::string Config::GetFullKey(const std::string& key, bool skipArrayIndex) {
int Config::BeginArray(const std::string& array) { int Config::BeginArray(const std::string& array) {
array_stack.push_back(ConfigArray{AdjustKey(array), 0, 0}); array_stack.push_back(ConfigArray{AdjustKey(array), 0, 0});
const int size = config->GetLongValue(GetSection().c_str(), GetFullKey(std::string("size"), true).c_str(), 0); const int size = config->GetLongValue(GetSection().c_str(), GetFullKey(std::string("size"), true).c_str(), 0);
array_stack.back().size = size;
return size;
array_stack.back().size = (std::max)(0, size);
return array_stack.back().size;
} }
void Config::EndArray() { void Config::EndArray() {
@ -1070,7 +1055,7 @@ void Config::EndArray() {
// Edge-case where the first array created doesn't have a name // Edge-case where the first array created doesn't have a name
config->SetValue(GetSection().c_str(), std::string("size").c_str(), ToString(size).c_str()); config->SetValue(GetSection().c_str(), std::string("size").c_str(), ToString(size).c_str());
} else { } else {
const auto key = GetFullKey(std::string("size"), true);
auto const key = GetFullKey(std::string("size"), true);
config->SetValue(GetSection().c_str(), key.c_str(), ToString(size).c_str()); config->SetValue(GetSection().c_str(), key.c_str(), ToString(size).c_str());
} }

15
src/input_common/drivers/udp_client.cpp

@ -31,8 +31,10 @@ public:
using clock = std::chrono::system_clock; using clock = std::chrono::system_clock;
explicit Socket(const std::string& host, u16 port, SocketCallback callback_) explicit Socket(const std::string& host, u16 port, SocketCallback callback_)
: callback(std::move(callback_)), timer(io_context),
socket(io_context, udp::endpoint(udp::v4(), 0)), client_id(Common::Random::Random32(0)) {
: callback(std::move(callback_)), timer(io_context)
, socket(io_context, udp::endpoint(udp::v4(), 0))
, client_id(Common::Random::Random32(0))
{
boost::system::error_code ec{}; boost::system::error_code ec{};
auto ipv4 = boost::asio::ip::make_address_v4(host, ec); auto ipv4 = boost::asio::ip::make_address_v4(host, ec);
if (ec.value() != boost::system::errc::success) { if (ec.value() != boost::system::errc::success) {
@ -353,8 +355,13 @@ PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const {
} }
Common::UUID UDPClient::GetHostUUID(const std::string& host) const { Common::UUID UDPClient::GetHostUUID(const std::string& host) const {
const auto ip = boost::asio::ip::make_address_v4(host);
const auto hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint());
boost::system::error_code ec{};
auto ip = boost::asio::ip::make_address_v4(host, ec);
if (ec.value() != boost::system::errc::success) {
LOG_ERROR(Input, "Invalid IPv4 address \"{}\" provided", host);
ip = boost::asio::ip::address_v4{};
}
auto const hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint());
return Common::UUID{hex_host}; return Common::UUID{hex_host};
} }

8
src/yuzu/game/game_list.cpp

@ -183,7 +183,7 @@ void GameList::ResetViewMode() {
tree_view->setVisible(false); tree_view->setVisible(false);
break; break;
default: default:
break;
UNREACHABLE();
} }
auto view = m_currentView->viewport(); auto view = m_currentView->viewport();
@ -196,10 +196,8 @@ void GameList::ResetViewMode() {
auto scroller = QScroller::scroller(view); auto scroller = QScroller::scroller(view);
QScrollerProperties props; QScrollerProperties props;
props.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy,
QScrollerProperties::OvershootAlwaysOff);
props.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy,
QScrollerProperties::OvershootAlwaysOff);
props.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
props.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
scroller->setScrollerProperties(props); scroller->setScrollerProperties(props);
if (m_isTreeMode != newTreeMode) { if (m_isTreeMode != newTreeMode) {

2
tools/README.md

@ -28,6 +28,8 @@ Tools for Eden and other subprojects. When adding new scripts please use `#!/bin
- `clang-format.sh`: Runs `clang-format` on the entire codebase. - `clang-format.sh`: Runs `clang-format` on the entire codebase.
* Requires: clang * Requires: clang
- `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin). - `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin).
- `cpp-lint.sh`: Homemade dumb C++ linter.
- `fuzzsettings.cpp`: Fuzz settings files.
## Android ## Android
It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI. It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI.

11
tools/fuzzsettings.cpp

@ -30,7 +30,9 @@ int main(int argc, char *argv[]) {
if (value == "true" || value == "false") { if (value == "true" || value == "false") {
new_line += std::string{} + "=TreufLAlse857874FJJakshjryiu475" + '\n'; new_line += std::string{} + "=TreufLAlse857874FJJakshjryiu475" + '\n';
} else if (std::isdigit(value[0])) { } else if (std::isdigit(value[0])) {
if (new_line == "size" || std::strstr(new_line.c_str(), "entries\\size") != nullptr) {
if (new_line == "size"
|| std::strstr(new_line.c_str(), "entries\\size") != nullptr
|| std::strstr(new_line.c_str(), "\\size")) {
new_line += "=-1\n"; new_line += "=-1\n";
} else { } else {
new_line += '=' + std::to_string(int(std::rand())) + '\n'; new_line += '=' + std::to_string(int(std::rand())) + '\n';
@ -46,7 +48,12 @@ int main(int argc, char *argv[]) {
} }
std::printf("%s", new_line.c_str()); std::printf("%s", new_line.c_str());
} else { } else {
std::printf("%s", line);
// yes default
*p = '\0';
std::string new_line{line};
std::string value{p + 1};
new_line += "=false\n";
std::printf("%s", new_line.c_str());
} }
} }
} }

Loading…
Cancel
Save