fix problem with GD not starting up through Steam

This commit is contained in:
HJfod 2022-10-11 22:00:08 +03:00
parent 66285aeadf
commit 69d7604e9d
5 changed files with 38 additions and 15 deletions
loader
include/Geode/loader
launcher/windows
src

View file

@ -3,6 +3,7 @@
#include "Event.hpp"
#include <optional>
#include "Setting.hpp"
#include "Loader.hpp"
namespace geode {
class GEODE_DLL SettingChangedEvent : public Event {
@ -67,5 +68,30 @@ namespace geode {
m_targetKey(std::nullopt),
m_consumer(handler) {}
};
template<class T>
requires std::is_base_of_v<Setting, T>
std::monostate listenForSettingChanges(
std::string const& settingID,
void(*callback)(std::shared_ptr<T>)
) {
Loader::get()->scheduleOnModLoad(getMod(), [=]() {
static SettingChangedEventHandler<T> _(
getMod()->getID(), settingID, callback
);
});
return std::monostate();
}
static std::monostate listenForAllSettingChanges(
void(*callback)(std::shared_ptr<Setting>)
) {
Loader::get()->scheduleOnModLoad(getMod(), [=]() {
static SettingChangedEventHandler<Setting> _(
getMod()->getID(), callback
);
});
return std::monostate();
}
}

View file

@ -6,16 +6,17 @@ void showError(std::string const& error) {
MessageBoxA(nullptr, error.c_str(), "Error Loading Geode", MB_ICONERROR);
}
int loadGeode() {
int loadGeode(PVOID module) {
if (!LoadLibraryW(L"Geode.dll")) {
auto code = GetLastError();
showError("Unable to load Geode (code " + std::to_string(code) + ")");
return code;
}
FreeLibraryAndExitThread(static_cast<HINSTANCE>(module), 0);
return 0;
}
DWORD WINAPI load(PVOID _) {
DWORD WINAPI load(PVOID module) {
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
auto resourcesDir = workingDir / "geode" / "resources";
@ -49,16 +50,17 @@ DWORD WINAPI load(PVOID _) {
}
}
return loadGeode();
return loadGeode(module);
}
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
if (reason == DLL_PROCESS_ATTACH) {
HANDLE handle = CreateThread(NULL, 0, load, module, 0, NULL);
if (handle)
if (handle) {
CloseHandle(handle);
else
} else {
return FALSE;
}
}
return TRUE;
}

View file

@ -166,8 +166,6 @@ namespace geode::core::impl {
// DobbyDestroy(at);
// DobbyHook(at, to, &trampolines()[at]);
static auto _ = MH_Initialize();
MH_RemoveHook(at);
MH_CreateHook(at, to, &trampolines()[at]);
MH_EnableHook(at);
@ -175,7 +173,7 @@ namespace geode::core::impl {
}
bool geode::core::hook::initialize() {
return true;
return MH_Initialize() == MH_OK;
}
#endif

View file

@ -2,7 +2,7 @@
#include "about.hpp"
#include "InternalLoader.hpp"
static auto SUPPORT_INFO = R"MD(
static constexpr const char* SUPPORT_INFO = R"MD(
**Geode** is funded through your gracious <cy>**donations**</c>!
You can support our work by sending <cp>**catgirl pictures**</c> to [HJfod](user:104257) :))
)MD";

View file

@ -54,9 +54,6 @@ __attribute__((constructor)) void _entry() {
#include <Windows.h>
DWORD WINAPI loadThread(void* arg) {
auto module = GetModuleHandleA("GeodeBootstrapper.dll");
FreeLibrary(module);
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
@ -91,9 +88,9 @@ BOOL WINAPI DllMain(HINSTANCE lib, DWORD reason, LPVOID) {
}
#endif
static SettingChangedEventHandler<BoolSetting> _(
"geode.loader", "show-platform-console",
[](auto setting) {
static auto _ = listenForSettingChanges(
"show-platform-console",
+[](std::shared_ptr<BoolSetting> setting) {
if (setting->getValue()) {
Loader::get()->openPlatformConsole();
} else {