From 705b81a9e38adeed333ae81db79a8af70ab80199 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 11 Sep 2022 00:16:31 +0200 Subject: [PATCH] Set VPK compression level through ConVar --- r5dev/tier1/IConVar.cpp | 9 +++++---- r5dev/tier1/cvar.cpp | 1 + r5dev/tier1/cvar.h | 1 + r5dev/vpklib/packedstore.cpp | 30 ++++++++++++++++++++++++++---- r5dev/vpklib/packedstore.h | 1 + 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index 41510e52..c4a68c9a 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -178,10 +178,11 @@ void ConVar::Init(void) const #endif // !DEDICATED //------------------------------------------------------------------------- // FILESYSTEM | - fs_warning_level_sdk = ConVar::Create("fs_warning_level_sdk" , "0", FCVAR_DEVELOPMENTONLY, "Set the SDK filesystem warning level.", false, 0.f, false, 0.f, nullptr, nullptr); - fs_show_warning_output = ConVar::Create("fs_show_warning_output" , "0", FCVAR_DEVELOPMENTONLY, "Logs the filesystem warnings to the console, filtered by 'fs_warning_level_native' ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); - fs_packedstore_entryblock_stats = ConVar::Create("fs_packedstore_entryblock_stats" , "0", FCVAR_DEVELOPMENTONLY, "If set to 1, prints the stats of each file entry in the VPK during decompression ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); - fs_packedstore_workspace = ConVar::Create("fs_packedstore_workspace", "platform/vpk/", FCVAR_DEVELOPMENTONLY, "Determines the current VPK workspace.", false, 0.f, false, 0.f, nullptr, nullptr); + fs_warning_level_sdk = ConVar::Create("fs_warning_level_sdk" , "0", FCVAR_DEVELOPMENTONLY, "Set the SDK filesystem warning level.", false, 0.f, false, 0.f, nullptr, nullptr); + fs_show_warning_output = ConVar::Create("fs_show_warning_output" , "0", FCVAR_DEVELOPMENTONLY, "Logs the filesystem warnings to the console, filtered by 'fs_warning_level_native' ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); + fs_packedstore_entryblock_stats = ConVar::Create("fs_packedstore_entryblock_stats" , "0", FCVAR_DEVELOPMENTONLY, "If set to 1, prints the stats of each file entry in the VPK during decompression ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); + fs_packedstore_workspace = ConVar::Create("fs_packedstore_workspace" , "platform/vpk/", FCVAR_DEVELOPMENTONLY, "Determines the current VPK workspace.", false, 0.f, false, 0.f, nullptr, nullptr); + fs_packedstore_compression_level = ConVar::Create("fs_packedstore_compression_level", "default", FCVAR_DEVELOPMENTONLY, "Determines the VPK compression level.", false, 0.f, false, 0.f, nullptr, "fastest faster default better uber"); //------------------------------------------------------------------------- // MATERIALSYSTEM | #ifndef DEDICATED diff --git a/r5dev/tier1/cvar.cpp b/r5dev/tier1/cvar.cpp index 9f1ce7fe..ba77993c 100644 --- a/r5dev/tier1/cvar.cpp +++ b/r5dev/tier1/cvar.cpp @@ -149,6 +149,7 @@ ConVar* fs_warning_level_sdk = nullptr; ConVar* fs_show_warning_output = nullptr; ConVar* fs_packedstore_entryblock_stats = nullptr; ConVar* fs_packedstore_workspace = nullptr; +ConVar* fs_packedstore_compression_level = nullptr; //----------------------------------------------------------------------------- // MATERIALSYSTEM | #ifndef DEDICATED diff --git a/r5dev/tier1/cvar.h b/r5dev/tier1/cvar.h index e8993bc8..03864f14 100644 --- a/r5dev/tier1/cvar.h +++ b/r5dev/tier1/cvar.h @@ -144,6 +144,7 @@ extern ConVar* fs_warning_level_sdk; extern ConVar* fs_show_warning_output; extern ConVar* fs_packedstore_entryblock_stats; extern ConVar* fs_packedstore_workspace; +extern ConVar* fs_packedstore_compression_level; //------------------------------------------------------------------------- // MATERIALSYSTEM | #ifndef DEDICATED diff --git a/r5dev/vpklib/packedstore.cpp b/r5dev/vpklib/packedstore.cpp index 37e69866..8bf5262b 100644 --- a/r5dev/vpklib/packedstore.cpp +++ b/r5dev/vpklib/packedstore.cpp @@ -20,8 +20,8 @@ void CPackedStore::InitLzCompParams(void) { /*| PARAMETERS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/ m_lzCompParams.m_dict_size_log2 = VPK_DICT_SIZE; - m_lzCompParams.m_level = lzham_compress_level::LZHAM_COMP_LEVEL_UBER; - m_lzCompParams.m_compress_flags = lzham_compress_flags::LZHAM_COMP_FLAG_DETERMINISTIC_PARSING | lzham_compress_flags::LZHAM_COMP_FLAG_TRADEOFF_DECOMPRESSION_RATE_FOR_COMP_RATIO; + m_lzCompParams.m_level = GetCompressionLevel(); + m_lzCompParams.m_compress_flags = lzham_compress_flags::LZHAM_COMP_FLAG_DETERMINISTIC_PARSING; m_lzCompParams.m_max_helper_threads = -1; } @@ -61,7 +61,7 @@ VPKDir_t CPackedStore::GetDirectoryFile(string svPackDirFile) const { if (svPackDirFile.find(DIR_CONTEXT[j]) != string::npos) { - string svPackDirPrefix = DIR_LOCALE[i] + DIR_LOCALE[i]; + const string svPackDirPrefix = DIR_LOCALE[i] + DIR_LOCALE[i]; StringReplace(svPackDirFile, DIR_LOCALE[i], svPackDirPrefix); goto escape; } @@ -93,6 +93,28 @@ string CPackedStore::GetPackFile(const string& svPackDirFile, uint16_t iArchiveI return svPackChunkFile; } +//----------------------------------------------------------------------------- +// Purpose: gets the LZHAM compression level +// output : lzham_compress_level +//----------------------------------------------------------------------------- +lzham_compress_level CPackedStore::GetCompressionLevel(void) const +{ + const char* pszLevel = fs_packedstore_compression_level->GetString(); + + if(strcmp(pszLevel, "fastest") == NULL) + return lzham_compress_level::LZHAM_COMP_LEVEL_FASTEST; + else if (strcmp(pszLevel, "faster") == NULL) + return lzham_compress_level::LZHAM_COMP_LEVEL_FASTER; + else if (strcmp(pszLevel, "default") == NULL) + return lzham_compress_level::LZHAM_COMP_LEVEL_DEFAULT; + else if (strcmp(pszLevel, "better") == NULL) + return lzham_compress_level::LZHAM_COMP_LEVEL_BETTER; + else if (strcmp(pszLevel, "uber") == NULL) + return lzham_compress_level::LZHAM_COMP_LEVEL_UBER; + else + return lzham_compress_level::LZHAM_COMP_LEVEL_DEFAULT; +} + //----------------------------------------------------------------------------- // Purpose: obtains and returns the entry block to the vector // Input : *pReader - @@ -109,7 +131,7 @@ vector CPackedStore::GetEntryBlocks(CIOStream* pReader) const { while (!(svName = pReader->ReadString()).empty()) { - string svFilePath = FormatEntryPath(svPath, svName, svExtension); + const string svFilePath = FormatEntryPath(svPath, svName, svExtension); vBlocks.push_back(VPKEntryBlock_t(pReader, svFilePath)); } } diff --git a/r5dev/vpklib/packedstore.h b/r5dev/vpklib/packedstore.h index 4bfdd265..5dc539a2 100644 --- a/r5dev/vpklib/packedstore.h +++ b/r5dev/vpklib/packedstore.h @@ -125,6 +125,7 @@ public: VPKDir_t GetDirectoryFile(string svDirectoryFile) const; string GetPackFile(const string& svPackDirFile, uint16_t iArchiveIndex) const; + lzham_compress_level GetCompressionLevel(void) const; vector GetEntryBlocks(CIOStream* pReader) const; vector GetEntryPaths(const string& svPathIn) const;