check if the user has loaded dlls and show a warning if so

This commit is contained in:
HJfod 2023-01-24 10:28:43 +02:00
parent 0ab93ee0a2
commit 0012762c84
7 changed files with 97 additions and 0 deletions

View file

@ -79,6 +79,8 @@ namespace geode {
bool didLastLaunchCrash() const;
bool userTriedToLoadDLLs() const;
friend class LoaderImpl;
friend Mod* takeNextLoaderMod();

View file

@ -90,6 +90,28 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
}
}
// show if the user tried to be naughty and load arbitary DLLs
static bool shownTriedToLoadDlls = false;
if (!shownTriedToLoadDlls) {
shownTriedToLoadDlls = true;
if (Loader::get()->userTriedToLoadDLLs()) {
log::debug("did try to load");
auto popup = FLAlertLayer::create(
"Hold up!",
"It appears that you have tried to <cr>load DLLs</c> with Geode. "
"Please note that <cy>Geode is incompatible with ALL DLLs</c>, "
"as they can cause Geode mods to <cr>error</c>, or even "
"<cr>crash</c>.\n\n"
"Remove the DLLs / other mod loaders you have, or <cr>proceed at "
"your own risk.</c>",
"OK"
);
popup->m_scene = this;
popup->m_noElasticity = true;
popup->show();
}
}
// show crash info
static bool shownLastCrash = false;
if (Loader::get()->didLastLaunchCrash() && !shownLastCrash) {

View file

@ -122,3 +122,7 @@ bool Loader::didLastLaunchCrash() const {
Mod* Loader::takeNextMod() {
return m_impl->takeNextMod();
}
bool Loader::userTriedToLoadDLLs() const {
return m_impl->userTriedToLoadDLLs();
}

View file

@ -136,6 +136,8 @@ namespace geode {
Mod* createInternalMod();
Result<> setupInternalMod();
bool userTriedToLoadDLLs() const;
};
class LoaderImpl {

View file

@ -32,4 +32,8 @@ void Loader::Impl::setupIPC() {
log::warning("IPC is not supported on this platform");
}
std::optional<std::vector<std::string>> Loader::Impl::userTriedToLoadDLLs() const {
return std::nullopt;
}
#endif

View file

@ -64,4 +64,8 @@ void Loader::Impl::setupIPC() {
log::debug("IPC set up");
}
std::optional<std::vector<std::string>> Loader::Impl::userTriedToLoadDLLs() const {
return std::nullopt;
}
#endif

View file

@ -3,11 +3,14 @@
#include <loader/ModImpl.hpp>
#include <iostream>
#include <loader/LoaderImpl.hpp>
#include <Geode/utils/string.hpp>
USE_GEODE_NAMESPACE();
#ifdef GEODE_IS_WINDOWS
#include <Psapi.h>
static constexpr auto IPC_BUFFER_SIZE = 512;
void Loader::Impl::platformMessageBox(char const* title, std::string const& info) {
@ -100,4 +103,60 @@ void Loader::Impl::setupIPC() {
log::debug("IPC set up");
}
bool Loader::Impl::userTriedToLoadDLLs() const {
static std::unordered_set<std::string> KNOWN_MOD_DLLS {
"betteredit-v4.0.5.dll",
"betteredit-v4.0.5-min.dll",
"betteredit-v4.0.3.dll",
"betteredit.dll",
"gdshare-v0.3.4.dll",
"gdshare.dll",
"hackpro.dll",
"hackproldr.dll",
"quickldr.dll",
"minhook.x32.dll",
"iconsave.dll",
"menuanim.dll",
"volumecontrol.dll",
"customsplash.dll",
"scrollanyinput-v1.1.dll",
"alttabfix-v1.0.dll",
"sceneswitcher-v1.1.dll",
"gdantialiasing.dll",
"textureldr.dll",
"run-info.dll",
};
bool triedToLoadDLLs = false;
// Check for .DLLs in mods dir
if (auto files = file::listFiles(dirs::getModsDir(), true)) {
for (auto& file : files.unwrap()) {
if (file.extension() == ".dll") {
triedToLoadDLLs = true;
}
}
}
// Check all loaded DLLs in the process
std::array<HMODULE, 1024> mods;
DWORD needed;
auto process = GetCurrentProcess();
if (EnumProcessModules(process, mods.data(), mods.size(), &needed)) {
for (auto i = 0; i < (needed / sizeof(HMODULE)); i++) {
std::array<char, MAX_PATH> modName;
if (GetModuleFileNameExA(process, mods[i], modName.data(), modName.size())) {
if (KNOWN_MOD_DLLS.count(string::trim(string::toLower(
ghc::filesystem::path(modName.data()).filename().string()
)))) {
triedToLoadDLLs = true;
}
}
}
}
return triedToLoadDLLs;
}
#endif