mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-21 01:49:31 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 313c7390ca | |||
| ab1a3a19e1 | |||
| 4fa1d8e2c5 | |||
| b060e25ee2 |
+3
-3
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
|
||||
set(CMAKE_GENERATOR_PLATFORM win32)
|
||||
|
||||
@@ -10,9 +10,9 @@ if(NOT(CMAKE_SIZEOF_VOID_P EQUAL 4))
|
||||
endif()
|
||||
|
||||
set(VERSION_MAJOR 1)
|
||||
set(VERSION_MINOR 7)
|
||||
set(VERSION_MINOR 8)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION_TWEAK 2)
|
||||
set(VERSION_TWEAK 1)
|
||||
|
||||
set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${VERSION_RC}" @ONLY)
|
||||
|
||||
@@ -14,7 +14,7 @@ export struct TexEntry {
|
||||
|
||||
namespace {
|
||||
HashType GetCrcFromFilename(const std::string& filename) {
|
||||
const static std::regex re(R"(0x[0-9a-f]{4,16})", std::regex::optimize | std::regex::icase);
|
||||
const static std::regex re(R"(0[xX][0-9a-fA-F]{4,16})", std::regex::optimize);
|
||||
std::smatch match;
|
||||
if (!std::regex_search(filename, match, re)) {
|
||||
return 0;
|
||||
@@ -117,13 +117,14 @@ void ParseSimpleArchive(const libzippp::ZipArchive& archive, std::vector<TexEntr
|
||||
for (const auto& entry : archive.getEntries()) {
|
||||
if (!entry.isFile())
|
||||
continue;
|
||||
const auto crc_hash = GetCrcFromFilename(entry.getName());
|
||||
const auto entry_name = entry.getName();
|
||||
const auto crc_hash = GetCrcFromFilename(entry_name);
|
||||
if (!crc_hash)
|
||||
continue;
|
||||
const auto data_ptr = static_cast<uint8_t*>(entry.readAsBinary());
|
||||
const auto size = entry.getSize();
|
||||
std::vector vec(data_ptr, data_ptr + size);
|
||||
std::filesystem::path tex_name(entry.getName());
|
||||
std::filesystem::path tex_name(entry_name);
|
||||
entries.emplace_back(std::move(vec), crc_hash, tex_name.extension().string());
|
||||
delete[] data_ptr;
|
||||
}
|
||||
|
||||
+4
-4
@@ -37,20 +37,20 @@ struct TextureFileStruct {
|
||||
inline void Message([[maybe_unused]] const char* format, ...)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
#if 0
|
||||
//const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
//[[maybe_unused]] const auto success = SetConsoleTextAttribute(hConsole, 0); // white
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Info([[maybe_unused]] const char* format, ...)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
[[maybe_unused]] const auto success = SetConsoleTextAttribute(hConsole, 0); // white
|
||||
//const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
//[[maybe_unused]] const auto success = SetConsoleTextAttribute(hConsole, 0); // white
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
|
||||
@@ -32,3 +32,4 @@
|
||||
|
||||
extern unsigned int gl_ErrorState;
|
||||
extern HINSTANCE gl_hThisInstance;
|
||||
inline std::filesystem::path gmod_dll_path;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace {
|
||||
bool use_64_bit_crc = false;
|
||||
|
||||
HashType GetCrcFromFilename(const std::string& filename) {
|
||||
const static std::regex re(R"(0x[0-9a-f]{4,16})", std::regex::optimize | std::regex::icase);
|
||||
const static std::regex re(R"(0[xX][0-9a-fA-F]{4,16})", std::regex::optimize);
|
||||
std::smatch match;
|
||||
if (!std::regex_search(filename, match, re)) {
|
||||
return 0;
|
||||
@@ -124,9 +124,12 @@ void ParseSimpleArchive(const libzippp::ZipArchive& archive, std::vector<TexEntr
|
||||
for (const auto& entry : archive.getEntries()) {
|
||||
if (!entry.isFile())
|
||||
continue;
|
||||
const auto entry_name = entry.getName();
|
||||
const auto crc_hash = GetCrcFromFilename(entry.getName());
|
||||
if (!crc_hash)
|
||||
if (!crc_hash) {
|
||||
Warning("Entry with name %s could not be parsed", entry_name.c_str());
|
||||
continue;
|
||||
}
|
||||
const auto data_ptr = static_cast<BYTE*>(entry.readAsBinary());
|
||||
const auto size = entry.getSize();
|
||||
std::vector vec(data_ptr, data_ptr + size);
|
||||
@@ -143,8 +146,10 @@ void ParseTexmodArchive(std::vector<std::string>& lines, libzippp::ZipArchive& a
|
||||
// match[1] | match[2]
|
||||
const static auto address_file_regex = std::regex(R"(^[\\/.]*([^|]+)\|([^\r\n]+))", std::regex::optimize);
|
||||
std::smatch match;
|
||||
if (!std::regex_search(line, match, address_file_regex))
|
||||
if (!std::regex_search(line, match, address_file_regex)) {
|
||||
Warning("Failed to parse texmod.def archive line: %s - %s", line.c_str(), line.c_str());
|
||||
continue;
|
||||
}
|
||||
const auto address_string = match[1].str();
|
||||
const auto file_path = match[2].str();
|
||||
|
||||
|
||||
@@ -154,20 +154,21 @@ 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 {};
|
||||
Message("Initialize: loading file %s... ", modfile.c_str());
|
||||
const auto modfile_str = modfile.string();
|
||||
Message("Initialize: loading file %s... ", modfile_str.c_str());
|
||||
auto file_loader = ModfileLoader(modfile);
|
||||
auto entries = file_loader.GetContents();
|
||||
if (entries.empty()) {
|
||||
@@ -179,7 +180,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();
|
||||
}
|
||||
@@ -198,6 +199,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());
|
||||
@@ -218,7 +222,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) {
|
||||
@@ -235,7 +239,7 @@ void TextureClient::LoadModsFromModlist(std::pair<std::string, std::string> modf
|
||||
}
|
||||
should_update = true;
|
||||
}
|
||||
Message("Finished loading mods from %s: Loaded %u bytes (%u mb)", modfile_tuple.first.c_str(), loaded_size, loaded_size / 1024 / 1024);
|
||||
Message("Finished loading mods from %s: Loaded %u bytes (%u mb)\n", modfile_tuple.first.c_str(), loaded_size, loaded_size / 1024 / 1024);
|
||||
}
|
||||
|
||||
void TextureClient::Initialize()
|
||||
@@ -316,7 +320,7 @@ int TextureClient::RemoveTexture(uModTexturePtr auto pTexture)
|
||||
|
||||
int TextureClient::LookUpToMod(uModTexturePtr auto pTexture)
|
||||
{
|
||||
Message("TextureClient::LookUpToMod( %p): hash: %#lX, %p\n", pTexture, pTexture->Hash, this);
|
||||
Message("TextureClient::LookUpToMod( %p): hash: %#lX\n", pTexture, pTexture->Hash);
|
||||
int ret = RETURN_OK;
|
||||
|
||||
if (pTexture->CrossRef_D3Dtex != nullptr)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user