r5sdk/r5dev/vpklib/packedstore.h

75 lines
3.6 KiB
C
Raw Normal View History

Code base refactor + major performance and readability improvement. Read description for details. * Codebase restructured to SourceSDK codebase style and .cpp/.h assertion paths in the game executable. * Document most functions with valve style 'Purpose' blocks. * Rename variables to match the rest of the codebase and Valve's naming convention. * Dedicated DLL and the SDKLauncher now share the same codebase as the DevSDK. * Obtain globals or pointers directly instead of waiting for runtime initialized data. * Dynamically search for all functions and globals (this doesn't count for dedicated yet!). * Initialize most in-SDK variables. * Move certain prints and other utilities under ConVars to reduce verbosity and increase performance. * Print all pattern scan results through a virtual function to make it easier to add and debug new patterns in the future. * Type global var pointers appropriately if class or type is known and implemented. * Forward declare 'CClient' class to avoid having 2 'g_pClient' copies. * Add IDA's pseudo definitions for easier prototyping with decompiled assembly code. * RPAK decompress Command callback implementation. * Load decompressed RPaks from 'paks\Win32\' overriding the ones in 'paks\Win64\' (the decompress callback will automatically fix the header and write it to 'paks\Win32\'). * VPK decompress Command callback implementation. * Move CRC32 ands Adler32 to implementation files. * Server will print out more details about the connecting client. * Upgrade ImGui lib to v1.86. * Don't compile id3dx.h for dedicated. * Don't compile id3dx.cpp for dedicated * Implement DevMsg print function allowing to print information to the in-game VGUI/RUI console overlay, ImGui console overlay and the external windows console * Fixed bug where the Error function would not properly terminate the process when an error is called. This caused access violations for critical/non-recoverable errors. * Fixed bug where the game would crash if the console or server browser was enabled while the game was still starting up. * Several bug fixes for the dedicated server (warning: dedicated is still considered work-in-progress!).
2021-12-25 22:36:38 +01:00
#pragma once
#include "public/include/binstream.h"
#include "thirdparty/lzham/include/lzham.h"
constexpr unsigned int LIBRARY_PACKS = 2;
constexpr unsigned int LANGUAGE_PACKS = 11;
constexpr unsigned int RVPK_DICT_SIZE = 20;
constexpr unsigned int RVPK_DIR_MAGIC = 'U<EFBFBD>4';
const std::string DIR_LIBRARY_PREFIX[LIBRARY_PACKS] = { "server", "client" };
const std::string DIR_LOCALE_PREFIX[LANGUAGE_PACKS] = { "english", "french", "german", "italian", "japanese", "korean", "polish", "portuguese", "russian", "spanish", "tchinese" };
struct vpk_entry_h
{
uint32_t m_nEntryFlags {}; // Entry flags.
uint16_t m_nTextureFlags {}; // Texture flags (only used if the entry is a vtf).
uint64_t m_nArchiveOffset {}; // Offset in archive.
uint64_t m_nCompressedSize {}; // Compressed size of entry.
uint64_t m_nUncompressedSize{}; // Uncompressed size of entry.
bool m_bIsCompressed = false;
vpk_entry_h(CIOStream* reader);
};
struct vpk_entry_block
{
uint32_t m_nCrc32 {}; // Crc32 for the uncompressed block.
uint16_t m_nPreloadBytes{}; // Preload bytes.
uint16_t m_iArchiveIndex{}; // Index of the archive that contains this block.
std::vector<vpk_entry_h> m_vvEntries {}; // Vector of all the entries of a given block (entries have a size limit of 1 MiB, so anything over is split into separate entries within the same block).
std::string m_svBlockPath {}; // Path to block within vpk.
vpk_entry_block(CIOStream* reader, std::string path);
};
struct vpk_dir_h
{
uint32_t m_nFileMagic {}; // File magic.
uint16_t m_nMajorVersion{}; // Vpk major version.
uint16_t m_nMinorVersion{}; // Vpk minor version.
uint32_t m_nTreeSize {}; // Directory tree size.
uint32_t m_nFileDataSize{}; // File data section size.
std::vector<vpk_entry_block> m_vvEntryBlocks{}; // Vector of entry blocks.
uint16_t m_iArchiveCount{}; // Highest archive index (archive count-1).
std::vector<std::string> m_vsvArchives {}; // Vector of archive file names.
std::string m_svDirPath {}; // Path to vpk_dir file.
vpk_dir_h(std::string path);
};
class CPackedStore
{
std::vector<uint8_t> m_vHashBuffer {}; // Buffer for post decomp file validation.
std::size_t m_nEntryCount {}; // Entry per-block incrementor.
lzham_uint32 m_nAdler32_Internal{}; // Internal operation Adler32 file checksum.
lzham_uint32 m_nAdler32 {}; // Pre/post operation Adler32 file checksum.
lzham_uint32 m_nCrc32_Internal {}; // Internal operation Crc32 file checksum.
lzham_uint32 m_nCrc32 {}; // Pre/post operation Crc32 file checksum.
lzham_decompress_params m_lzDecompParams {}; // LZham decompression parameters.
lzham_decompress_status_t m_lzDecompStatus {}; // LZham decompression results.
public:
void InitLzParams();
vpk_dir_h GetPackDirFile(std::string svPackDirFile);
std::string GetPackChunkFile(std::string svPackDirFile, int iArchiveIndex);
std::vector<vpk_entry_block> GetEntryBlocks(CIOStream* reader);
std::string FormatBlockPath(std::string svName, std::string svPath, std::string svExtension);
std::string StripLocalePrefix(std::string svPackDirFile);
void UnpackAll(vpk_dir_h vpk, std::string svPathOut = "");
void ValidateAdler32PostDecomp(std::string svDirAsset);
void ValidateCRC32PostDecomp(std::string svDirAsset);
};
///////////////////////////////////////////////////////////////////////////////
extern CPackedStore* g_pPackedStore;