diff --git a/loader/src/platform/windows/main.cpp b/loader/src/platform/windows/main.cpp index dd02a901..6f6c7b82 100644 --- a/loader/src/platform/windows/main.cpp +++ b/loader/src/platform/windows/main.cpp @@ -138,11 +138,25 @@ void* mainTrampolineAddr; #include "gdTimestampMap.hpp" unsigned int gdTimestamp = 0; +// In case the game is launched from a different directory through command line +// this function will set the current working directory to the game's directory +// to avoid the game crashing due to not being able to find the resources +void fixCurrentWorkingDirectory() { + std::array cwd; + + auto size = GetModuleFileNameW(nullptr, cwd.data(), cwd.size()); + if (size == cwd.size()) return; + + SetCurrentDirectoryW(std::filesystem::path(cwd.data()).parent_path().wstring().c_str()); +} + int WINAPI gdMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { // MessageBoxA(NULL, "Hello from gdMainHook!", "Hi", 0); updateGeode(); + fixCurrentWorkingDirectory(); + if (versionToTimestamp(GEODE_STR(GEODE_GD_VERSION)) > gdTimestamp) { console::messageBox( "Unable to Load Geode!",