ObjLoading: Add basis for IPakEntryReadStream to read ipak entries

This commit is contained in:
Jan
2020-02-08 15:55:10 +01:00
parent 5bda400acb
commit 00d7997d0a
8 changed files with 275 additions and 27 deletions

View File

@ -112,32 +112,39 @@ void ObjLoaderT6::LoadImageFromIwi(T6::GfxImage* image, ISearchPath* searchPath,
Texture* loadedTexture = nullptr;
IwiLoader loader(zone->GetMemory());
const std::string imageFileName = "images/" + std::string(image->name) + ".iwi";
auto* filePathImage = searchPath->Open(imageFileName);
if (filePathImage != nullptr && filePathImage->IsOpen())
{
loadedTexture = loader.LoadIwi(filePathImage);
filePathImage->Close();
delete filePathImage;
}
else if (image->streamedPartCount > 0)
if (image->streamedPartCount > 0)
{
for (auto* ipak : IPak::Repository)
{
auto* ipakEntry = ipak->GetEntryData(image->hash, image->streamedParts[0].hash);
auto* ipakStream = ipak->GetEntryStream(image->hash, image->streamedParts[0].hash);
if (ipakEntry != nullptr && ipakEntry->IsOpen())
if (ipakStream != nullptr)
{
loadedTexture = loader.LoadIwi(ipakEntry);
loadedTexture = loader.LoadIwi(ipakStream);
ipakEntry->Close();
delete ipakEntry;
ipakStream->Close();
delete ipakStream;
if (loadedTexture != nullptr)
break;
}
}
}
if(loadedTexture == nullptr)
{
const std::string imageFileName = "images/" + std::string(image->name) + ".iwi";
auto* filePathImage = searchPath->Open(imageFileName);
if (filePathImage != nullptr)
{
loadedTexture = loader.LoadIwi(filePathImage);
filePathImage->Close();
delete filePathImage;
}
}
if(loadedTexture != nullptr)
{
image->texture.texture = loadedTexture;