Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions header/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@

extern unsigned int gl_ErrorState;
extern HINSTANCE gl_hThisInstance;
inline std::filesystem::path gmod_dll_path;
13 changes: 8 additions & 5 deletions modules/TextureClient.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ int TextureClient::UnlockMutex()
return RETURN_OK;
}

gsl::owner<TextureFileStruct*> AddFile(TexEntry& entry, const bool compress, const std::filesystem::path& dll_path)
gsl::owner<TextureFileStruct*> 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<BYTE*>(dds_blob.GetBufferPointer()), static_cast<BYTE*>(dds_blob.GetBufferPointer()) + dds_blob.GetBufferSize());
return texture_file_struct;
}

std::vector<gsl::owner<TextureFileStruct*>> ProcessModfile(const std::filesystem::path& modfile, const std::filesystem::path& dll_path, const bool compress)
std::vector<gsl::owner<TextureFileStruct*>> ProcessModfile(const std::filesystem::path& modfile, const bool compress)
{
const auto hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
if (FAILED(hr)) return {};
Expand All @@ -179,7 +179,7 @@ std::vector<gsl::owner<TextureFileStruct*>> 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();
}
Expand All @@ -198,6 +198,9 @@ void TextureClient::LoadModsFromModlist(std::pair<std::string, std::string> modf
std::string line;
std::vector<std::filesystem::path> 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());
Expand All @@ -218,7 +221,7 @@ void TextureClient::LoadModsFromModlist(std::pair<std::string, std::string> modf
}
std::vector<std::future<std::vector<gsl::owner<TextureFileStruct*>>>> 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) {
Expand Down
9 changes: 4 additions & 5 deletions modules/TextureFunction.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -408,7 +407,7 @@ export namespace TextureFunction {
}

#ifdef _DEBUG
ImageSave(compressed_image, entry, dll_path);
ImageSave(compressed_image, entry);
#endif
return dds_blob;
}
Expand Down
3 changes: 3 additions & 0 deletions source/dll_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down