move loadGeode call to geode's DllMain

This commit is contained in:
ConfiG 2023-06-11 00:33:17 +03:00
parent 9031328821
commit 9acb07229b
No known key found for this signature in database
GPG key ID: 44DA1983F524C11B
3 changed files with 15 additions and 22 deletions
loader
launcher/windows
src/platform/windows

View file

@ -1,2 +1 @@
#include <Windows.h>
__declspec(dllexport) DWORD WINAPI loadGeode(void* arg) { return 0; }
__declspec(dllexport) void fake() { }

View file

@ -5,23 +5,10 @@
#pragma comment(linker, "/export:XInputSetState=xinput1_4.XInputSetState")
#pragma comment(linker, "/export:XInputGetCapabilities=xinput1_4.XInputGetCapabilities")
__declspec(dllimport) void fake();
DWORD XInputGetDSoundAudioDeviceGuids(DWORD user, GUID* render, GUID* capture) {
fake();
return ERROR_BAD_ARGUMENTS;
}
#pragma comment(linker, "/export:XInputGetDSoundAudioDeviceGuids=_XInputGetDSoundAudioDeviceGuids")
__declspec(dllimport) DWORD WINAPI loadGeode(void*);
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
if (reason == DLL_PROCESS_ATTACH) {
// Prevents threads from notifying this DLL on creation or destruction.
// Kind of redundant for a game that isn't multi-threaded but will provide
// some slight optimizations if a mod frequently creates and deletes threads.
DisableThreadLibraryCalls(module);
DWORD code = loadGeode(module);
if (code != 0)
return FALSE;
}
return TRUE;
}

View file

@ -42,7 +42,7 @@ int WINAPI gdMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
return reinterpret_cast<decltype(&wWinMain)>(geode::base::get() + 0x260ff8)(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
extern "C" __declspec(dllexport) DWORD WINAPI loadGeode(void* arg) {
bool loadGeode(void* arg) {
auto process = GetCurrentProcess();
auto patchAddr = reinterpret_cast<void*>(geode::base::get() + 0x260ff8);
@ -68,10 +68,10 @@ extern "C" __declspec(dllexport) DWORD WINAPI loadGeode(void* arg) {
"There was an unknown fatal error hooking "
"the GD main function and Geode can not be loaded."
);
return 1;
return false;
}
return 0;
return true;
}
DWORD WINAPI upgradeThread(void*) {
@ -79,16 +79,23 @@ DWORD WINAPI upgradeThread(void*) {
return 0;
}
extern "C" __declspec(dllexport) void fake() { }
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) {
// Prevents threads from notifying this DLL on creation or destruction.
// Kind of redundant for a game that isn't multi-threaded but will provide
// some slight optimizations if a mod frequently creates and deletes threads.
DisableThreadLibraryCalls(module);
// if we find the old bootstrapper dll, don't load geode, copy new updater and let it do the rest
auto workingDir = dirs::getGameDir();
auto error = std::error_code();
if (ghc::filesystem::exists(workingDir / "GeodeBootstrapper.dll", error) && !error)
bool oldBootstrapperExists = ghc::filesystem::exists(workingDir / "GeodeBootstrapper.dll", error);
if (oldBootstrapperExists && !error)
CreateThread(nullptr, 0, upgradeThread, nullptr, 0, nullptr);
if (error)
else if (error)
return FALSE;
else if (!loadGeode(module))
return FALSE;
}
return TRUE;