2022-10-08 05:41:36 -04:00
|
|
|
#include <Windows.h>
|
2022-10-08 06:21:57 -04:00
|
|
|
#include <iostream>
|
2022-10-08 05:41:36 -04:00
|
|
|
#include "../../../filesystem/fs/filesystem.hpp"
|
|
|
|
|
2022-10-08 06:21:57 -04:00
|
|
|
int loadGeode() {
|
|
|
|
auto dll = LoadLibraryA("Geode.dll");
|
|
|
|
if (!dylib) {
|
|
|
|
std::cout << "Couldn't open Geode: " << GetLastError() << std::endl;
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-08 05:41:36 -04:00
|
|
|
DWORD WINAPI load(PVOID _) {
|
|
|
|
auto workingDir = ghc::filesystem::current_path();
|
|
|
|
auto updatesDir = workingDir / "geode" / "update";
|
|
|
|
auto resourcesDir = workingDir / "geode" / "resources";
|
|
|
|
|
|
|
|
auto error = std::error_code();
|
|
|
|
|
|
|
|
if (ghc::filesystem::exists(updatesDir / "Geode.dll", error) && !error) {
|
|
|
|
ghc::filesystem::rename(
|
|
|
|
updatesDir / "Geode.dll",
|
|
|
|
workingDir / "Geode.dll", error
|
|
|
|
);
|
2022-10-08 06:21:57 -04:00
|
|
|
if (error) {
|
|
|
|
std::cout << "Couldn't update Geode: " << error.message() << std::endl;
|
|
|
|
return loadGeode();
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
|
2022-10-08 06:21:57 -04:00
|
|
|
std::filesystem::remove_all(resourcesDir / "geode.loader", error);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
|
|
|
|
return loadGeode();
|
|
|
|
}
|
|
|
|
|
2022-10-08 05:41:36 -04:00
|
|
|
ghc::filesystem::rename(
|
|
|
|
updatesDir / "resources",
|
|
|
|
resourcesDir / "geode.loader", error
|
|
|
|
);
|
2022-10-08 06:21:57 -04:00
|
|
|
if (error) {
|
|
|
|
std::cout << "Couldn't update Geode resources: " << error.message() << std::endl;
|
|
|
|
return loadGeode();
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
}
|
|
|
|
|
2022-10-08 06:21:57 -04:00
|
|
|
return loadGeode();
|
2022-10-08 05:41:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
|
|
|
|
if (reason == DLL_PROCESS_ATTACH) {
|
|
|
|
HANDLE handle = CreateThread(NULL, 0, load, module, 0, NULL);
|
|
|
|
if (handle)
|
|
|
|
CloseHandle(handle);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|