Skip to content

Commit

Permalink
Fix uiia texture export sizes (#125)
Browse files Browse the repository at this point in the history
Co-authored-by: Quity <quity@quity.dev>
  • Loading branch information
quityobs and Quity authored Jul 25, 2023
1 parent dcf475e commit dcf953d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Legion/src/Assets/uiia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,10 @@ void RpakLib::ExtractUIIA(const RpakLoadAsset& Asset, std::unique_ptr<Assets::Te
RpakStream->SetPosition(this->GetFileOffset(Asset, Asset.RawDataIndex, Asset.RawDataOffset));
RpakStream->Read((uint8_t*)&RImage, 0, sizeof(RUIImage));

if (RImage.HighResolutionWidth + UnpackedShiftWidth > 2)
RImage.HighResolutionWidth += UnpackedShiftWidth;
if (RImage.HighResolutionHeight + UnpackedShiftHeight > 2)
RImage.HighResolutionHeight += UnpackedShiftHeight;
if (RImage.LowResolutionWidth + UnpackedShiftWidth > 2)
RImage.LowResolutionWidth += UnpackedShiftWidth;
if (RImage.LowResolutionHeight + UnpackedShiftHeight > 2)
RImage.LowResolutionHeight += UnpackedShiftHeight;

bool UseHighResolution = StarpakStream != nullptr;

uint32_t WidthBlocks = UseHighResolution ? (RImage.HighResolutionWidth + 29) / 31 : (RImage.LowResolutionWidth + 29) / 31;
uint32_t HeightBlocks = UseHighResolution ? (RImage.HighResolutionHeight + 29) / 31 : (RImage.LowResolutionHeight + 29) / 31;
uint32_t WidthBlocks = ((UseHighResolution ? RImage.HighResolutionWidth : RImage.LowResolutionWidth) + UnpackedShiftWidth + 29) / 31;
uint32_t HeightBlocks = ((UseHighResolution ? RImage.HighResolutionHeight : RImage.LowResolutionHeight) + UnpackedShiftHeight + 29) / 31;
uint32_t TotalBlocks = WidthBlocks * HeightBlocks;
uint32_t Width = WidthBlocks * 32;
uint32_t Height = HeightBlocks * 32;
Expand Down Expand Up @@ -439,5 +430,20 @@ void RpakLib::ExtractUIIA(const RpakLoadAsset& Asset, std::unique_ptr<Assets::Te
Texture = std::move(Bc7Texture);
}
}

uint16_t OutWidth = UseHighResolution ? RImage.HighResolutionWidth : RImage.LowResolutionWidth;
uint16_t OutHeight = UseHighResolution ? RImage.HighResolutionHeight : RImage.LowResolutionHeight;
auto FinalTexture = std::make_unique<Assets::Texture>(OutWidth, OutHeight, DXGI_FORMAT::DXGI_FORMAT_R8G8B8A8_UNORM);

for (uint32_t y = 0; y < HeightBlocks; y++)
{
uint32_t SizeY = y * 31 + 30 < OutHeight ? 31 : OutHeight - y * 31;
for (uint32_t x = 0; x < WidthBlocks; x++)
{
uint32_t SizeX = x * 31 + 30 < OutWidth ? 31 : OutWidth - x * 31;
FinalTexture->CopyTextureSlice(Texture, { (x * 32), (y * 32), SizeX, SizeY }, (x * 31), (y * 31));
}
}
Texture = std::move(FinalTexture);
}
}

0 comments on commit dcf953d

Please sign in to comment.