From 71dabb52e1e78ee05af2ea760a1cfca9c694997c Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Sun, 13 Feb 2022 17:07:02 +0100 Subject: [PATCH] RTech var renames and struct renames. --- r5dev/rtech/rtech_utils.cpp | 12 +++---- r5dev/rtech/rtech_utils.h | 18 +++++------ r5dev/tier0/completion.cpp | 62 ++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index b8ae83c9..d56b3ffd 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -62,7 +62,7 @@ std::uint64_t __fastcall RTech::StringToGuid(const char* pData) //----------------------------------------------------------------------------- // Purpose: calculate 'decompressed' size and commit parameters //----------------------------------------------------------------------------- -std::uint32_t __fastcall RTech::DecompressPakFileInit(rpak_decomp_state* state, std::uint8_t* fileBuffer, std::int64_t fileSize, std::int64_t offNoHeader, std::int64_t headerSize) +std::uint32_t __fastcall RTech::DecompressPakFileInit(RPakDecompState_t* state, std::uint8_t* fileBuffer, std::int64_t fileSize, std::int64_t offNoHeader, std::int64_t headerSize) { std::int64_t input_byte_pos_init; // r9 std::uint64_t byte_init; // r11 @@ -136,7 +136,7 @@ std::uint32_t __fastcall RTech::DecompressPakFileInit(rpak_decomp_state* state, result = state->m_nDecompSize; inv_mask_out = state->m_nInvMaskOut; qw70 = offNoHeader + state->m_nInvMaskIn - 6i64; - state->len_needed = stream_len_needed + offNoHeader; + state->m_nLengthNeeded = stream_len_needed + offNoHeader; state->qword70 = qw70; state->byte = byte_final; state->byte_bit_offset = byte_bit_offset_final; @@ -156,7 +156,7 @@ std::uint32_t __fastcall RTech::DecompressPakFileInit(rpak_decomp_state* state, //----------------------------------------------------------------------------- // Purpose: decompress input data //----------------------------------------------------------------------------- -std::uint8_t __fastcall RTech::DecompressPakFile(rpak_decomp_state* state, std::uint64_t inLen, std::uint64_t outLen) +std::uint8_t __fastcall RTech::DecompressPakFile(RPakDecompState_t* state, std::uint64_t inLen, std::uint64_t outLen) { std::uint64_t decompressed_position; // r15 std::uint32_t byte_bit_offset; // ebp @@ -216,7 +216,7 @@ std::uint8_t __fastcall RTech::DecompressPakFile(rpak_decomp_state* state, std:: std::uint64_t v68; // rcx std::uint8_t result; // al - if (inLen < state->len_needed) + if (inLen < state->m_nLengthNeeded) return 0; decompressed_position = state->m_nDecompPosition; @@ -450,9 +450,9 @@ std::uint8_t __fastcall RTech::DecompressPakFile(rpak_decomp_state* state, std:: input_byte_pos += header_skip_bytes_bs; stream_decompressed_size_new = decompressed_position + state->m_nInvMaskOut + 1; v36 = *(std::uint64_t*)(v34 + state->m_nInputBuf) & ((1LL << (8 * (std::uint8_t)header_skip_bytes_bs)) - 1); - len_needed_new = v36 + state->len_needed; + len_needed_new = v36 + state->m_nLengthNeeded; stream_compressed_size_new = v36 + state->m_nCompressedStreamSize; - state->len_needed = len_needed_new; + state->m_nLengthNeeded = len_needed_new; state->m_nCompressedStreamSize = stream_compressed_size_new; if (stream_decompressed_size_new >= decompressed_size) diff --git a/r5dev/rtech/rtech_utils.h b/r5dev/rtech/rtech_utils.h index 0b7dc057..93a3fc3c 100644 --- a/r5dev/rtech/rtech_utils.h +++ b/r5dev/rtech/rtech_utils.h @@ -50,7 +50,7 @@ namespace #pragma warning( pop ) } -struct rpak_h +struct RPakApexHeader_t { std::uint32_t m_nMagic; // 'RPak' std::uint16_t m_nVersion; // R2 = '7' R5 = '8' @@ -70,21 +70,21 @@ struct rpak_h std::uint32_t m_nPatchIndex; // - std::uint32_t m_nUnknownThirdBlockCount; // + std::uint32_t m_nDescriptorCount; // std::uint32_t m_nAssetEntryCount; // File entry count - std::uint32_t m_nUnknownFifthBlockCount; // - std::uint32_t m_nUnknownSixedBlockCount; // + std::uint32_t m_nGuidDescriptorCount; // + std::uint32_t m_nRelationsCounts; // std::uint8_t unk2[0x1C]; // }; -struct __declspec(align(8)) rpak_patch_compress_header +struct __declspec(align(8)) RPakPatchCompressedHeader_t { std::uint64_t m_nSizeDisk; std::uint64_t m_nSizeMemory; }; -struct __declspec(align(8)) rpak_decomp_state +struct __declspec(align(8)) RPakDecompState_t { std::uint64_t m_nInputBuf; std::uint64_t m_nOut; @@ -98,7 +98,7 @@ struct __declspec(align(8)) rpak_decomp_state std::uint32_t dword44; std::uint64_t input_byte_pos; std::uint64_t m_nDecompPosition; - std::uint64_t len_needed; + std::uint64_t m_nLengthNeeded; std::uint64_t byte; std::uint32_t byte_bit_offset; std::uint32_t dword6C; @@ -121,8 +121,8 @@ class RTech { public: std::uint64_t __fastcall StringToGuid(const char* pData); - std::uint8_t __fastcall DecompressPakFile(rpak_decomp_state* state, std::uint64_t inLen, std::uint64_t outLen); - std::uint32_t __fastcall DecompressPakFileInit(rpak_decomp_state* state, std::uint8_t* fileBuffer, std::int64_t fileSize, std::int64_t offNoHeader, std::int64_t headerSize); + std::uint8_t __fastcall DecompressPakFile(RPakDecompState_t* state, std::uint64_t inLen, std::uint64_t outLen); + std::uint32_t __fastcall DecompressPakFileInit(RPakDecompState_t* state, std::uint8_t* fileBuffer, std::int64_t fileSize, std::int64_t offNoHeader, std::int64_t headerSize); }; /////////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/tier0/completion.cpp b/r5dev/tier0/completion.cpp index c1c6aeaa..055edd7d 100644 --- a/r5dev/tier0/completion.cpp +++ b/r5dev/tier0/completion.cpp @@ -408,34 +408,34 @@ void _RTech_Decompress_f_CompletionFunc(CCommand* cmd) std::string firstArg = args[1]; // Get first arg. std::string secondArg = args[2]; // Get second arg. - const std::string mod_dir = "paks\\Win32\\"; - const std::string base_dir = "paks\\Win64\\"; + const std::string modDir = "paks\\Win32\\"; + const std::string baseDir = "paks\\Win64\\"; - std::string pak_name_out = mod_dir + firstArg + ".rpak"; - std::string pak_name_in = base_dir + firstArg + ".rpak"; + std::string pakNameOut = modDir + firstArg + ".rpak"; + std::string pakNameIn = baseDir + firstArg + ".rpak"; - CreateDirectories(pak_name_out); + CreateDirectories(pakNameOut); DevMsg(eDLL_T::RTECH, "______________________________________________________________\n"); DevMsg(eDLL_T::RTECH, "] RTECH_DECOMPRESS -------------------------------------------\n"); - if (!FileExists(pak_name_in.c_str())) + if (!FileExists(pakNameIn.c_str())) { - DevMsg(eDLL_T::RTECH, "Error: pak file '%s' does not exist!\n", pak_name_in.c_str()); + DevMsg(eDLL_T::RTECH, "Error: pak file '%s' does not exist!\n", pakNameIn.c_str()); return; } - DevMsg(eDLL_T::RTECH, "] Processing: '%s'\n", pak_name_in.c_str()); + DevMsg(eDLL_T::RTECH, "] Processing: '%s'\n", pakNameIn.c_str()); std::vector upak; // Compressed region. - std::ifstream ipak(pak_name_in, std::fstream::binary); + std::ifstream ipak(pakNameIn, std::fstream::binary); ipak.seekg(0, std::fstream::end); upak.resize(ipak.tellg()); ipak.seekg(0, std::fstream::beg); ipak.read((char*)upak.data(), upak.size()); - rpak_h* rheader = (rpak_h*)upak.data(); + RPakApexHeader_t* rheader = (RPakApexHeader_t*)upak.data(); uint16_t flags = (rheader->m_nFlags[0] << 8) | rheader->m_nFlags[1]; DevMsg(eDLL_T::RTECH, "______________________________________________________________\n"); @@ -453,70 +453,70 @@ void _RTech_Decompress_f_CompletionFunc(CCommand* cmd) if (rheader->m_nMagic != 'kaPR') { - DevMsg(eDLL_T::RTECH, "Error: pak file '%s' has invalid magic!\n", pak_name_in.c_str()); + DevMsg(eDLL_T::RTECH, "Error: pak file '%s' has invalid magic!\n", pakNameIn.c_str()); return; } if ((rheader->m_nFlags[1] & 1) != 1) { - DevMsg(eDLL_T::RTECH, "Error: pak file '%s' already decompressed!\n", pak_name_in.c_str()); + DevMsg(eDLL_T::RTECH, "Error: pak file '%s' already decompressed!\n", pakNameIn.c_str()); return; } if (rheader->m_nSizeDisk != upak.size()) { - DevMsg(eDLL_T::RTECH, "Error: pak file '%s' decompressed size '%u' doesn't match expected value '%u'!\n", pak_name_in.c_str(), upak.size(), rheader->m_nSizeMemory); + DevMsg(eDLL_T::RTECH, "Error: pak file '%s' decompressed size '%u' doesn't match expected value '%u'!\n", pakNameIn.c_str(), upak.size(), rheader->m_nSizeMemory); return; } - rpak_decomp_state state; - std::uint32_t dsize = g_pRtech->DecompressPakFileInit(&state, upak.data(), upak.size(), 0, PAK_HEADER_SIZE); + RPakDecompState_t state; + std::uint32_t decompSize = g_pRtech->DecompressPakFileInit(&state, upak.data(), upak.size(), 0, PAK_HEADER_SIZE); - if (dsize == rheader->m_nSizeDisk) + if (decompSize == rheader->m_nSizeDisk) { - DevMsg(eDLL_T::RTECH, "Error: calculated size: '%zu' expected: '%zu'!\n", dsize, rheader->m_nSizeMemory); + DevMsg(eDLL_T::RTECH, "Error: calculated size: '%zu' expected: '%zu'!\n", decompSize, rheader->m_nSizeMemory); return; } else { - DevMsg(eDLL_T::RTECH, "] Calculated size: '%zu'\n", dsize); + DevMsg(eDLL_T::RTECH, "] Calculated size: '%zu'\n", decompSize); } - std::vector pakbuf(rheader->m_nSizeMemory, 0); + std::vector pakBuf(rheader->m_nSizeMemory, 0); state.m_nOutMask = UINT64_MAX; - state.m_nOut = uint64_t(pakbuf.data()); + state.m_nOut = uint64_t(pakBuf.data()); - std::uint8_t decomp_result = g_pRtech->DecompressPakFile(&state, upak.size(), pakbuf.size()); - if (decomp_result != 1) + std::uint8_t decompResult = g_pRtech->DecompressPakFile(&state, upak.size(), pakBuf.size()); + if (decompResult != 1) { - DevMsg(eDLL_T::RTECH, "Error: decompression failed for '%s' return value: '%u'!\n", pak_name_in.c_str(), +decomp_result); + DevMsg(eDLL_T::RTECH, "Error: decompression failed for '%s' return value: '%u'!\n", pakNameIn.c_str(), +decompResult); return; } rheader->m_nFlags[1] = 0x0; // Set compressed flag to false for the decompressed pak file rheader->m_nSizeDisk = rheader->m_nSizeMemory; // Equal compressed size with decompressed - std::ofstream out_block(pak_name_out, std::fstream::binary); + std::ofstream outBlock(pakNameOut, std::fstream::binary); if (rheader->m_nPatchIndex > 0) // Check if its an patch rpak. { // Loop through all the structs and patch their compress size. - for (int i = 1, patch_offset = 0x88; i <= rheader->m_nPatchIndex; i++, patch_offset += sizeof(rpak_patch_compress_header)) + for (int i = 1, patch_offset = 0x88; i <= rheader->m_nPatchIndex; i++, patch_offset += sizeof(RPakPatchCompressedHeader_t)) { - rpak_patch_compress_header* patch_header = (rpak_patch_compress_header*)((std::uintptr_t)pakbuf.data() + patch_offset); + RPakPatchCompressedHeader_t* patch_header = (RPakPatchCompressedHeader_t*)((std::uintptr_t)pakBuf.data() + patch_offset); patch_header->m_nSizeDisk = patch_header->m_nSizeMemory; // Fix size for decompress. } } - memcpy_s(pakbuf.data(), state.m_nDecompSize, ((std::uint8_t*)rheader), PAK_HEADER_SIZE); // Overwrite first 0x80 bytes which are NULL with the header data. + memcpy_s(pakBuf.data(), state.m_nDecompSize, ((std::uint8_t*)rheader), PAK_HEADER_SIZE); // Overwrite first 0x80 bytes which are NULL with the header data. - out_block.write((char*)pakbuf.data(), state.m_nDecompSize); + outBlock.write((char*)pakBuf.data(), state.m_nDecompSize); uint32_t crc32_init = {}; - DevMsg(eDLL_T::RTECH, "] CRC32 : '%08X'\n", crc32::update(crc32_init, pakbuf.data(), state.m_nDecompSize)); - DevMsg(eDLL_T::RTECH, "] Decompressed rpak to: '%s'\n", pak_name_out.c_str()); + DevMsg(eDLL_T::RTECH, "] CRC32 : '%08X'\n", crc32::update(crc32_init, pakBuf.data(), state.m_nDecompSize)); + DevMsg(eDLL_T::RTECH, "] Decompressed rpak to: '%s'\n", pakNameOut.c_str()); DevMsg(eDLL_T::RTECH, "--------------------------------------------------------------\n"); - out_block.close(); + outBlock.close(); } void _NET_TraceNetChan_f_CompletionFunc(CCommand* cmd)