[Filesystem] Use info from launcher (#440)

* [Filesystem] Use info from launcher
This commit is contained in:
Edo 2022-08-17 21:53:52 +02:00 committed by GitHub
parent bea07f6df2
commit ed617dc879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View File

@ -243,9 +243,9 @@ namespace Components
void FileSystem::RegisterFolder(const char* folder)
{
std::string fs_cdpath = Dvar::Var("fs_cdpath").get<std::string>();
std::string fs_basepath = Dvar::Var("fs_basepath").get<std::string>();
std::string fs_homepath = Dvar::Var("fs_homepath").get<std::string>();
const auto fs_cdpath = Dvar::Var("fs_cdpath").get<std::string>();
const auto fs_basepath = Dvar::Var("fs_basepath").get<std::string>();
const auto fs_homepath = Dvar::Var("fs_homepath").get<std::string>();
if (!fs_cdpath.empty()) Game::FS_AddLocalizedGameDirectory(fs_cdpath.data(), folder);
if (!fs_basepath.empty()) Game::FS_AddLocalizedGameDirectory(fs_basepath.data(), folder);
@ -323,6 +323,12 @@ namespace Components
Utils::Hook::Call<void(void*)>(0x4291A0)(iwd);
}
const char* FileSystem::Sys_DefaultInstallPath_Hk()
{
static auto current_path = std::filesystem::current_path().string();
return current_path.data();
}
FileSystem::FileSystem()
{
FileSystem::MemAllocator.clear();
@ -370,6 +376,9 @@ namespace Components
// Handle IWD freeing
Utils::Hook(0x642F60, FileSystem::IwdFreeStub, HOOK_CALL).install()->quick();
// Set the working dir based on info from the Xlabs launcher
Utils::Hook(0x4326E0, FileSystem::Sys_DefaultInstallPath_Hk, HOOK_JUMP).install()->quick();
}
FileSystem::~FileSystem()

View File

@ -116,5 +116,7 @@ namespace Components
static int LoadTextureSync(Game::GfxImageLoadDef **loadDef, Game::GfxImage *image);
static void IwdFreeStub(Game::iwd_t* iwd);
static const char* Sys_DefaultInstallPath_Hk();
};
}

View File

@ -106,13 +106,18 @@ namespace Utils
void SetEnvironment()
{
wchar_t exeName[512];
GetModuleFileNameW(GetModuleHandle(nullptr), exeName, sizeof(exeName) / sizeof(wchar_t));
char* buffer{};
std::size_t size{};
if (_dupenv_s(&buffer, &size, "XLABS_MW2_INSTALL") != 0 || buffer == nullptr)
{
return;
}
auto* exeBaseName = wcsrchr(exeName, L'\\');
exeBaseName[0] = L'\0';
const auto _0 = gsl::finally([&] { std::free(buffer); });
SetCurrentDirectoryW(exeName);
std::string dir{buffer, size};
SetCurrentDirectoryA(dir.data());
SetDllDirectoryA(dir.data());
}
HMODULE GetNTDLL()