Skip to content

Commit

Permalink
Add check for NahimicOSD.dll
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Jan 10, 2025
1 parent d6f94f2 commit 8a5b35a
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 16 deletions.
6 changes: 4 additions & 2 deletions scwx-qt/scwx-qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ find_package(Qt${QT_VERSION_MAJOR}
set(SRC_EXE_MAIN source/scwx/qt/main/main.cpp)

set(HDR_MAIN source/scwx/qt/main/application.hpp
source/scwx/qt/main/main_window.hpp)
source/scwx/qt/main/main_window.hpp
source/scwx/qt/main/process_validation.hpp)
set(SRC_MAIN source/scwx/qt/main/application.cpp
source/scwx/qt/main/main_window.cpp)
source/scwx/qt/main/main_window.cpp
source/scwx/qt/main/process_validation.cpp)
set(UI_MAIN source/scwx/qt/main/main_window.ui)
set(HDR_CONFIG source/scwx/qt/config/county_database.hpp
source/scwx/qt/config/radar_site.hpp)
Expand Down
7 changes: 6 additions & 1 deletion scwx-qt/source/scwx/qt/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <scwx/qt/config/county_database.hpp>
#include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/main/main_window.hpp>
#include <scwx/qt/main/process_validation.hpp>
#include <scwx/qt/main/versions.hpp>
#include <scwx/qt/manager/log_manager.hpp>
#include <scwx/qt/manager/radar_product_manager.hpp>
Expand Down Expand Up @@ -113,6 +114,9 @@ int main(int argc, char* argv[])
// Theme
ConfigureTheme(args);

// Check process modules for compatibility
scwx::qt::main::CheckProcessModules();

// Run initial setup if required
if (scwx::qt::ui::setup::SetupWizard::IsSetupRequired())
{
Expand Down Expand Up @@ -170,7 +174,8 @@ static void ConfigureTheme(const std::vector<std::string>& args)
QGuiApplication::styleHints()->setColorScheme(qtColorScheme);

std::optional<std::string> paletteFile;
if (uiStyle == scwx::qt::types::UiStyle::FusionCustom) {
if (uiStyle == scwx::qt::types::UiStyle::FusionCustom)
{
paletteFile = generalSettings.theme_file().GetValue();
}
else
Expand Down
109 changes: 109 additions & 0 deletions scwx-qt/source/scwx/qt/main/process_validation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <scwx/qt/main/process_validation.hpp>
#include <scwx/util/logger.hpp>

#if defined(_WIN32)
# include <scwx/qt/settings/general_settings.hpp>

# include <wtypes.h>
# include <Psapi.h>

# include <boost/algorithm/string/predicate.hpp>
# include <boost/locale.hpp>
# include <fmt/ranges.h>
# include <QCheckBox>
# include <QMessageBox>
#endif

namespace scwx::qt::main
{

static const std::string logPrefix_ = "scwx::qt::main::process_validation";
static const auto logger_ = util::Logger::Create(logPrefix_);

void CheckProcessModules()
{
#if defined(_WIN32)
HANDLE process = GetCurrentProcess();
HMODULE modules[1024];
DWORD cbNeeded = 0;

std::vector<std::string> incompatibleDlls {};
std::vector<std::string> descriptions {};

auto& processModuleWarningsEnabled =
settings::GeneralSettings::Instance().process_module_warnings_enabled();

if (EnumProcessModules(process, modules, sizeof(modules), &cbNeeded))
{
std::uint32_t numModules = cbNeeded / sizeof(HMODULE);
for (std::uint32_t i = 0; i < numModules; ++i)
{
char modulePath[MAX_PATH];
if (GetModuleFileNameExA(process, modules[i], modulePath, MAX_PATH))
{
std::string path = modulePath;

logger_->trace("DLL Found: {}", path);

if (boost::algorithm::iends_with(path, "NahimicOSD.dll"))
{
std::string description =
QObject::tr(
"ASUS Sonic Studio injects a Nahimic driver, which causes "
"Supercell Wx to hang. It is suggested to disable the "
"Nahimic service, or to uninstall ASUS Sonic Studio and "
"the Nahimic driver.")
.toStdString();

logger_->warn("Incompatible DLL found: {}", path);
logger_->warn("{}", description);

// Only populate vectors for the message box if warnings are
// enabled
if (processModuleWarningsEnabled.GetValue())
{
incompatibleDlls.push_back(path);
descriptions.push_back(description);
}
}
}
}
}

if (!incompatibleDlls.empty())
{
const std::string header =
QObject::tr(
"The following DLLs have been injected into the Supercell Wx "
"process:")
.toStdString();
const std::string defaultMessage =
QObject::tr(
"Supercell Wx is known to not run correctly with these DLLs "
"injected. We suggest stopping or uninstalling these services if "
"you experience crashes or unexpected behavior while using "
"Supercell Wx.")
.toStdString();

std::string message = fmt::format("{}\n\n{}\n\n{}\n\n{}",
header,
fmt::join(incompatibleDlls, "\n"),
defaultMessage,
fmt::join(descriptions, "\n"));

QMessageBox dialog(QMessageBox::Icon::Warning,
QObject::tr("Supercell Wx"),
QString::fromStdString(message));
QCheckBox* checkBox =
new QCheckBox(QObject::tr("Don't show this message again"), &dialog);
dialog.setCheckBox(checkBox);
dialog.exec();

// Stage the result of the checkbox. This value will be committed on
// shutdown.
processModuleWarningsEnabled.StageValue(!checkBox->isChecked());
}
#endif
}

} // namespace scwx::qt::main
8 changes: 8 additions & 0 deletions scwx-qt/source/scwx/qt/main/process_validation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace scwx::qt::main
{

void CheckProcessModules();

} // namespace scwx::qt::main
24 changes: 18 additions & 6 deletions scwx-qt/source/scwx/qt/settings/general_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class GeneralSettings::Impl
nmeaBaudRate_.SetDefault(9600);
nmeaSource_.SetDefault("");
positioningPlugin_.SetDefault(defaultPositioningPlugin);
processModuleWarningsEnabled_.SetDefault(true);
showMapAttribution_.SetDefault(true);
showMapCenter_.SetDefault(false);
showMapLogo_.SetDefault(true);
Expand Down Expand Up @@ -162,12 +163,14 @@ class GeneralSettings::Impl
SettingsVariable<std::int64_t> nmeaBaudRate_ {"nmea_baud_rate"};
SettingsVariable<std::string> nmeaSource_ {"nmea_source"};
SettingsVariable<std::string> positioningPlugin_ {"positioning_plugin"};
SettingsVariable<bool> showMapAttribution_ {"show_map_attribution"};
SettingsVariable<bool> showMapCenter_ {"show_map_center"};
SettingsVariable<bool> showMapLogo_ {"show_map_logo"};
SettingsVariable<std::string> theme_ {"theme"};
SettingsVariable<std::string> themeFile_ {"theme_file"};
SettingsVariable<bool> trackLocation_ {"track_location"};
SettingsVariable<bool> processModuleWarningsEnabled_ {
"process_module_warnings_enabled"};
SettingsVariable<bool> showMapAttribution_ {"show_map_attribution"};
SettingsVariable<bool> showMapCenter_ {"show_map_center"};
SettingsVariable<bool> showMapLogo_ {"show_map_logo"};
SettingsVariable<std::string> theme_ {"theme"};
SettingsVariable<std::string> themeFile_ {"theme_file"};
SettingsVariable<bool> trackLocation_ {"track_location"};
SettingsVariable<bool> updateNotificationsEnabled_ {"update_notifications"};
SettingsVariable<std::string> warningsProvider_ {"warnings_provider"};
SettingsVariable<bool> cursorIconAlwaysOn_ {"cursor_icon_always_on"};
Expand Down Expand Up @@ -197,6 +200,7 @@ GeneralSettings::GeneralSettings() :
&p->nmeaBaudRate_,
&p->nmeaSource_,
&p->positioningPlugin_,
&p->processModuleWarningsEnabled_,
&p->showMapAttribution_,
&p->showMapCenter_,
&p->showMapLogo_,
Expand Down Expand Up @@ -316,6 +320,11 @@ SettingsVariable<std::string>& GeneralSettings::positioning_plugin() const
return p->positioningPlugin_;
}

SettingsVariable<bool>& GeneralSettings::process_module_warnings_enabled() const
{
return p->processModuleWarningsEnabled_;
}

SettingsVariable<bool>& GeneralSettings::show_map_attribution() const
{
return p->showMapAttribution_;
Expand Down Expand Up @@ -374,6 +383,7 @@ bool GeneralSettings::Shutdown()
dataChanged |= p->loopDelay_.Commit();
dataChanged |= p->loopSpeed_.Commit();
dataChanged |= p->loopTime_.Commit();
dataChanged |= p->processModuleWarningsEnabled_.Commit();
dataChanged |= p->trackLocation_.Commit();

return dataChanged;
Expand Down Expand Up @@ -407,6 +417,8 @@ bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs)
lhs.p->nmeaBaudRate_ == rhs.p->nmeaBaudRate_ &&
lhs.p->nmeaSource_ == rhs.p->nmeaSource_ &&
lhs.p->positioningPlugin_ == rhs.p->positioningPlugin_ &&
lhs.p->processModuleWarningsEnabled_ ==
rhs.p->processModuleWarningsEnabled_ &&
lhs.p->showMapAttribution_ == rhs.p->showMapAttribution_ &&
lhs.p->showMapCenter_ == rhs.p->showMapCenter_ &&
lhs.p->showMapLogo_ == rhs.p->showMapLogo_ &&
Expand Down
13 changes: 7 additions & 6 deletions scwx-qt/source/scwx/qt/settings/general_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ class GeneralSettings : public SettingsCategory
SettingsVariable<std::int64_t>& nmea_baud_rate() const;
SettingsVariable<std::string>& nmea_source() const;
SettingsVariable<std::string>& positioning_plugin() const;
SettingsVariable<bool>& show_map_attribution() const;
SettingsVariable<bool>& show_map_center() const;
SettingsVariable<bool>& show_map_logo() const;
SettingsVariable<std::string>& theme() const;
SettingsVariable<std::string>& theme_file() const;
SettingsVariable<bool>& track_location() const;
SettingsVariable<bool>& process_module_warnings_enabled() const;
SettingsVariable<bool>& show_map_attribution() const;
SettingsVariable<bool>& show_map_center() const;
SettingsVariable<bool>& show_map_logo() const;
SettingsVariable<std::string>& theme() const;
SettingsVariable<std::string>& theme_file() const;
SettingsVariable<bool>& track_location() const;
SettingsVariable<bool>& update_notifications_enabled() const;
SettingsVariable<std::string>& warnings_provider() const;
SettingsVariable<bool>& cursor_icon_always_on() const;
Expand Down

0 comments on commit 8a5b35a

Please sign in to comment.