diff --git a/CMakeLists.txt b/CMakeLists.txt index 455eaaa..86b9342 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ endif() set(VERSION_MAJOR 1) set(VERSION_MINOR 7) set(VERSION_PATCH 0) -set(VERSION_TWEAK 2) +set(VERSION_TWEAK 3) set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${VERSION_RC}" @ONLY) diff --git a/header/Main.h b/header/Main.h index c08cbb5..e45e3a0 100644 --- a/header/Main.h +++ b/header/Main.h @@ -32,3 +32,4 @@ extern unsigned int gl_ErrorState; extern HINSTANCE gl_hThisInstance; +inline std::filesystem::path gmod_dll_path; diff --git a/modules/TextureClient.ixx b/modules/TextureClient.ixx index 1155abf..787bcb5 100644 --- a/modules/TextureClient.ixx +++ b/modules/TextureClient.ixx @@ -154,16 +154,16 @@ int TextureClient::UnlockMutex() return RETURN_OK; } -gsl::owner AddFile(TexEntry& entry, const bool compress, const std::filesystem::path& dll_path) +gsl::owner AddFile(TexEntry& entry, const bool compress) { const auto texture_file_struct = new TextureFileStruct(); texture_file_struct->crc_hash = entry.crc_hash; - const auto dds_blob = TextureFunction::ConvertToCompressedDDS(entry, compress, dll_path); + const auto dds_blob = TextureFunction::ConvertToCompressedDDS(entry, compress); texture_file_struct->data.assign(static_cast(dds_blob.GetBufferPointer()), static_cast(dds_blob.GetBufferPointer()) + dds_blob.GetBufferSize()); return texture_file_struct; } -std::vector> ProcessModfile(const std::filesystem::path& modfile, const std::filesystem::path& dll_path, const bool compress) +std::vector> ProcessModfile(const std::filesystem::path& modfile, const bool compress) { const auto hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); if (FAILED(hr)) return {}; @@ -179,7 +179,7 @@ std::vector> ProcessModfile(const std::filesystem texture_file_structs.reserve(entries.size()); unsigned file_bytes_loaded = 0; for (auto& tpf_entry : entries) { - const auto tex_file_struct = AddFile(tpf_entry, compress, dll_path); + const auto tex_file_struct = AddFile(tpf_entry, compress); texture_file_structs.push_back(tex_file_struct); file_bytes_loaded += texture_file_structs.back()->data.size(); } @@ -198,6 +198,9 @@ void TextureClient::LoadModsFromModlist(std::pair modf std::string line; std::vector modfiles; while (std::getline(file, line)) { + if (line.starts_with("//") || line.starts_with("#") || line.empty()) { + continue; + } // Remove newline character line.erase(std::ranges::remove(line, '\r').begin(), line.end()); line.erase(std::ranges::remove(line, '\n').begin(), line.end()); @@ -218,7 +221,7 @@ void TextureClient::LoadModsFromModlist(std::pair modf } std::vector>>> futures; for (const auto modfile : modfiles) { - futures.emplace_back(std::async(std::launch::async, ProcessModfile, modfile, dll_path, files_size > 400'000'000)); + futures.emplace_back(std::async(std::launch::async, ProcessModfile, modfile, files_size > 400'000'000)); } auto loaded_size = 0u; for (auto& future : futures) { diff --git a/modules/TextureFunction.ixx b/modules/TextureFunction.ixx index 32b2e66..7b09302 100644 --- a/modules/TextureFunction.ixx +++ b/modules/TextureFunction.ixx @@ -338,10 +338,10 @@ export namespace TextureFunction { return compressed_image; } - void ImageSave(const DirectX::ScratchImage& image, const TexEntry& entry, const std::filesystem::path& dll_path) + void ImageSave(const DirectX::ScratchImage& image, const TexEntry& entry) { const auto file_name = std::format("0x{:x}.dds", entry.crc_hash); - const auto file_out = dll_path / "textures" / file_name; + const auto file_out = gmod_dll_path.parent_path() / "textures" / file_name; try { if (std::filesystem::exists(file_out)) { return; @@ -361,11 +361,10 @@ export namespace TextureFunction { } catch (const std::exception& e) { Warning("SaveDDSImageToDisk (%#lX%s): %s\n", entry.crc_hash, entry.ext.c_str(), e.what()); - return; } } - DirectX::Blob ConvertToCompressedDDS(TexEntry& entry, const bool compress, [[maybe_unused]] const std::filesystem::path& dll_path) + DirectX::Blob ConvertToCompressedDDS(TexEntry& entry, const bool compress) { DirectX::ScratchImage image; HRESULT hr = 0; @@ -408,7 +407,7 @@ export namespace TextureFunction { } #ifdef _DEBUG - ImageSave(compressed_image, entry, dll_path); + ImageSave(compressed_image, entry); #endif return dds_blob; } diff --git a/source/dll_main.cpp b/source/dll_main.cpp index 56e9eb1..5de38a2 100644 --- a/source/dll_main.cpp +++ b/source/dll_main.cpp @@ -185,6 +185,9 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserv switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { #ifdef _DEBUG + wchar_t dllFilePath[512 + 1]{}; + GetModuleFileNameW(hModule, dllFilePath, 512); + gmod_dll_path = dllFilePath; AllocConsole(); SetConsoleTitleA("gMod Console"); freopen_s(&stdout_proxy, "CONOUT$", "w", stdout);