mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 01:18:01 -05:00
Fixing current working directory on startup (#1047)
* add fix currect working directory * oops * change to wchar and use max_path * using `std::array` * Make the cwd fix use std filesystem path --------- Co-authored-by: IliasHDZ <nassimbennamari38@gmail.com> Co-authored-by: alk <45172705+altalk23@users.noreply.github.com>
This commit is contained in:
parent
ebd65caa2b
commit
7c558ee47e
1 changed files with 14 additions and 0 deletions
|
@ -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<WCHAR, MAX_PATH> 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!",
|
||||
|
|
Loading…
Reference in a new issue