Change way we retrieve and set paths in Options
Makes everything relative in some way from .exe, which should prove more reliable
@@ -8,19 +8,15 @@ static std::unique_ptr<Options> s_instance;
Options::Options(HMODULE aModule)
{
- char path[2048 + 1] = { 0 };
- GetModuleFileNameA(aModule, path, std::size(path) - 1);
- Path = path;
-
- char exePath[2048 + 1] = { 0 };
- GetModuleFileNameA(GetModuleHandleA(nullptr), exePath, std::size(exePath) - 1);
+ TCHAR exePath[2048 + 1] = { 0 };
+ GetModuleFileName(GetModuleHandle(nullptr), exePath, std::size(exePath) - 1);
ExePath = exePath;
- int verInfoSz = GetFileVersionInfoSizeA(exePath, nullptr);
+ int verInfoSz = GetFileVersionInfoSize(exePath, nullptr);
if(verInfoSz)
{
auto verInfo = std::make_unique<BYTE[]>(verInfoSz);
- if(GetFileVersionInfoA(exePath, 0, verInfoSz, verInfo.get()))
+ if(GetFileVersionInfo(exePath, 0, verInfoSz, verInfo.get()))
{
struct
{
@@ -29,16 +25,16 @@ Options::Options(HMODULE aModule)
} *pTranslations;
UINT transBytes = 0;
- if(VerQueryValueA(verInfo.get(), "\\VarFileInfo\\Translation", reinterpret_cast<void**>(&pTranslations), &transBytes))
+ if(VerQueryValue(verInfo.get(), _T("\\VarFileInfo\\Translation"), reinterpret_cast<void**>(&pTranslations), &transBytes))
{
UINT dummy;
char* productName = nullptr;
char subBlock[64];
for(UINT i = 0; i < (transBytes / sizeof(*pTranslations)); i++)
{
- sprintf_s(subBlock, "\\StringFileInfo\\%04x%04x\\ProductName", pTranslations[i].Language, pTranslations[i].CodePage);
- if(VerQueryValueA(verInfo.get(), subBlock, reinterpret_cast<void**>(&productName), &dummy))
- if (strcmp(productName, "Cyberpunk 2077") == 0)
+ _stprintf(subBlock, _T("\\StringFileInfo\\%04x%04x\\ProductName"), pTranslations[i].Language, pTranslations[i].CodePage);
+ if(VerQueryValue(verInfo.get(), subBlock, reinterpret_cast<void**>(&productName), &dummy))
+ if (_tcscmp(productName, _T("Cyberpunk 2077")) == 0)
{
ExeValid = true;
break;
@@ -48,14 +44,14 @@ Options::Options(HMODULE aModule)
}
}
// check if exe name matches in case previous check fails
- ExeValid = ExeValid || (ExePath.filename() == "Cyberpunk2077.exe");
+ ExeValid = ExeValid || (ExePath.filename() == _T("Cyberpunk2077.exe"));
if (!IsCyberpunk2077())
return;
- Path = Path.parent_path().parent_path();
- Path /= "plugins";
- Path /= "cyber_engine_tweaks/";
+ Path = ExePath.parent_path();
+ Path /= _T("plugins");
+ Path /= _T("cyber_engine_tweaks\\");
std::error_code ec;
create_directories(Path, ec);
@@ -72,6 +68,8 @@ Options::Options(HMODULE aModule)
{
auto [major, minor] = GameImage.GetVersion();
spdlog::info("Game version {}.{:02d}", major, minor);
+ spdlog::info("EXE path: \"{}\"", ExePath.string().c_str());
+ spdlog::info("Cyber Engine Tweaks path: \"{}\"", Path.string().c_str());
}
else
spdlog::info("Unknown Game Version, update the mod");
