From c3158b6937eb10cb49345bdc0f6fc128cdb7d8bb Mon Sep 17 00:00:00 2001 From: Marvin D <41352111+IcePixelx@users.noreply.github.com> Date: Sun, 4 Dec 2022 00:01:31 +0100 Subject: [PATCH] Slight improvements. CModule::GetSectionByName adjustments. RTech::CreateDXTexture improvements. --- r5dev/public/utility/module.cpp | 6 +++--- r5dev/rtech/rtech_utils.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/r5dev/public/utility/module.cpp b/r5dev/public/utility/module.cpp index aecf66b9..6e186377 100644 --- a/r5dev/public/utility/module.cpp +++ b/r5dev/public/utility/module.cpp @@ -305,10 +305,10 @@ CMemory CModule::GetVirtualMethodTable(const string& svTableName, const uint32_t //----------------------------------------------------------------------------- CModule::ModuleSections_t CModule::GetSectionByName(const string& svSectionName) const { - for (size_t i = 0; i < m_vModuleSections.size(); i++) + for (const ModuleSections_t& section : m_vModuleSections) { - if (m_vModuleSections[i].m_svSectionName.compare(svSectionName) == 0) - return m_vModuleSections[i]; + if (section.m_svSectionName == svSectionName) + return section; } return ModuleSections_t(); diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index 7f331071..7d3a8363 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -508,6 +508,7 @@ uint8_t __fastcall RTech::DecompressPakFile(RPakDecompState_t* state, uint64_t i // Disable stack warning, tells us to move more data to the heap instead. Not really possible with 'initialData' here. Since its parallel processed. // Also disable 6378, complains that there is no control path where it would use 'nullptr', if that happens 'Error' will be called though. #pragma warning( disable : 6262 6387) +constexpr uint32_t ALIGNMENT_SIZE = 15; // Used by the game in CreateDXTexture. //---------------------------------------------------------------------------------- // Purpose: creates 2D texture and shader resource from textureHeader and imageData. //---------------------------------------------------------------------------------- @@ -539,12 +540,12 @@ void RTech::CreateDXTexture(TextureHeader_t* textureHeader, int64_t imageData) uint8_t x = s_pBytesPerPixel[textureHeader->m_nImageFormat].first; uint8_t y = s_pBytesPerPixel[textureHeader->m_nImageFormat].second; - uint32_t bytesPerPixelWidth = (y + mipWidth) >> (y >> 1); - uint32_t bytesPerPixelHeight = (y + mipHeight) >> (y >> 1); + uint32_t bppWidth = (y + mipWidth) >> (y >> 1); + uint32_t bppHeight = (y + mipHeight) >> (y >> 1); uint32_t sliceWidth = x * (y >> (y >> 1)); - uint32_t rowPitch = sliceWidth * bytesPerPixelWidth; - uint32_t slicePitch = x * bytesPerPixelWidth * bytesPerPixelHeight; + uint32_t rowPitch = sliceWidth * bppWidth; + uint32_t slicePitch = x * bppWidth * bppHeight; uint32_t subResourceEntry = mipLevel; for (int i = 0; i < textureHeader->m_nArraySize; i++) @@ -555,7 +556,7 @@ void RTech::CreateDXTexture(TextureHeader_t* textureHeader, int64_t imageData) *(uint32_t*)((uint8_t*)&initialData[1] + offsetCurrentResourceData) = rowPitch; *(uint32_t*)((uint8_t*)&initialData[1] + offsetCurrentResourceData + 4) = slicePitch; - imageData += (slicePitch + 15) & 0xFFFFFFF0; + imageData += (slicePitch + ALIGNMENT_SIZE) & ~ALIGNMENT_SIZE; subResourceEntry += textureHeader->m_nPermanentMipCount; } }