From f5208d2b614f464e4c5394337e63889ac69b212d Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Mon, 27 Dec 2021 20:44:37 +0100 Subject: [PATCH] Fixed NET::ShutDown recursive calling, fixed decompressed patch header size on decompress. --- r5dev/engine/net_chan.cpp | 10 +++++++-- r5dev/rtech/rtech_utils.h | 45 +++++++++++++++++++++----------------- r5dev/tier0/completion.cpp | 10 +++++++++ 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/r5dev/engine/net_chan.cpp b/r5dev/engine/net_chan.cpp index 7f7a461d..77d65813 100644 --- a/r5dev/engine/net_chan.cpp +++ b/r5dev/engine/net_chan.cpp @@ -20,10 +20,10 @@ //----------------------------------------------------------------------------- // Purpose: shutdown netchannel //----------------------------------------------------------------------------- -void NET_ShutDown(void* thisptr, const char* szReason, std::uint8_t a1, char a2) +void HNET_ShutDown(void* thisptr, const char* szReason, std::uint8_t a1, char a2) { DownloadPlaylists_Callback(); // Re-load playlist from disk after getting disconnected from the server. - NET_ShutDown(thisptr, szReason, a1, a2); + NET_Shutdown(thisptr, szReason, a1, a2); } //----------------------------------------------------------------------------- @@ -154,11 +154,17 @@ void NET_DisconnectClient(CClient* pClient, int nIndex, const char* szReason, ui void CNetChan_Attach() { DetourAttach((LPVOID*)&NET_PrintFunc, &HNET_PrintFunc); +#ifndef DEDICATED + DetourAttach((LPVOID*)&NET_Shutdown, &HNET_ShutDown); +#endif } void CNetChan_Detach() { DetourDetach((LPVOID*)&NET_PrintFunc, &HNET_PrintFunc); +#ifndef DEDICATED + DetourDetach((LPVOID*)&NET_Shutdown, &HNET_ShutDown); +#endif } void CNetChan_Trace_Attach() diff --git a/r5dev/rtech/rtech_utils.h b/r5dev/rtech/rtech_utils.h index 3ad4ace5..0b7dc057 100644 --- a/r5dev/rtech/rtech_utils.h +++ b/r5dev/rtech/rtech_utils.h @@ -78,29 +78,34 @@ struct rpak_h std::uint8_t unk2[0x1C]; // }; +struct __declspec(align(8)) rpak_patch_compress_header +{ + std::uint64_t m_nSizeDisk; + std::uint64_t m_nSizeMemory; +}; + struct __declspec(align(8)) rpak_decomp_state { - uint64_t m_nInputBuf; - uint64_t m_nOut; - uint64_t m_nMask; - uint64_t m_nOutMask; - uint64_t m_nTotalFileLen; - uint64_t m_nDecompSize; - uint64_t m_nInvMaskIn; - uint64_t m_nInvMaskOut; - uint32_t header_skip_bytes_bs; - uint32_t dword44; - uint64_t input_byte_pos; - uint64_t m_nDecompPosition; - uint64_t len_needed; - uint64_t byte; - uint32_t byte_bit_offset; - uint32_t dword6C; - uint64_t qword70; - uint64_t m_nCompressedStreamSize; - uint64_t m_nDecompStreamSize; + std::uint64_t m_nInputBuf; + std::uint64_t m_nOut; + std::uint64_t m_nMask; + std::uint64_t m_nOutMask; + std::uint64_t m_nTotalFileLen; + std::uint64_t m_nDecompSize; + std::uint64_t m_nInvMaskIn; + std::uint64_t m_nInvMaskOut; + std::uint32_t header_skip_bytes_bs; + std::uint32_t dword44; + std::uint64_t input_byte_pos; + std::uint64_t m_nDecompPosition; + std::uint64_t len_needed; + std::uint64_t byte; + std::uint32_t byte_bit_offset; + std::uint32_t dword6C; + std::uint64_t qword70; + std::uint64_t m_nCompressedStreamSize; + std::uint64_t m_nDecompStreamSize; }; -static_assert(sizeof(rpak_decomp_state) == 0x88); namespace { diff --git a/r5dev/tier0/completion.cpp b/r5dev/tier0/completion.cpp index 1fb70566..f1ce5d42 100644 --- a/r5dev/tier0/completion.cpp +++ b/r5dev/tier0/completion.cpp @@ -492,6 +492,16 @@ void _RTech_Decompress_f_CompletionFunc(CCommand* cmd) std::ofstream out_block(pak_name_out, 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)) + { + rpak_patch_compress_header* patch_header = (rpak_patch_compress_header*)((std::uintptr_t)pakbuf.data() + patch_offset); + patch_header->m_nSizeDisk = patch_header->m_nSizeMemory; + } + } + 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);