mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
ObjLoading: Read index section of ipaks and try to open images from it when loading obj data
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
#include "Game/T6/GameT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
#include "ObjContainer/IPak/IPak.h"
|
||||
#include "ObjLoading.h"
|
||||
|
||||
const int ObjLoaderT6::IPAK_READ_HASH = Com_HashKey("ipak_read", 64);
|
||||
const int ObjLoaderT6::GLOBAL_HASH = Com_HashKey("GLOBAL", 64);
|
||||
@ -30,15 +31,36 @@ bool ObjLoaderT6::SupportsZone(Zone* zone)
|
||||
|
||||
void ObjLoaderT6::LoadIPakForZone(ISearchPath* searchPath, const std::string& ipakName, Zone* zone)
|
||||
{
|
||||
printf("Loading ipak '%s' for zone '%s'\n", ipakName.c_str(), zone->m_name.c_str());
|
||||
if(ObjLoading::Configuration.Verbose)
|
||||
{
|
||||
printf("Loading ipak '%s' for zone '%s'\n", ipakName.c_str(), zone->m_name.c_str());
|
||||
}
|
||||
|
||||
const std::string ipakFilename = ipakName + ".ipak";
|
||||
|
||||
auto* file = searchPath->Open(ipakFilename);
|
||||
|
||||
if(file && file->IsOpen())
|
||||
{
|
||||
|
||||
IPak* ipak = new IPak(ipakFilename, file);
|
||||
|
||||
if(ipak->Initialize())
|
||||
{
|
||||
IPak::Repository.AddContainer(ipak, zone);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ipak;
|
||||
file->Close();
|
||||
delete file;
|
||||
|
||||
printf("Failed to load ipak '%s'!\n", ipakFilename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if(ipakName == "base")
|
||||
{
|
||||
LoadIPakForZone(searchPath, "mp", zone);
|
||||
LoadIPakForZone(searchPath, "so", zone);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,11 +71,12 @@ void ObjLoaderT6::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone*
|
||||
|
||||
if(assetPoolT6->m_key_value_pairs != nullptr)
|
||||
{
|
||||
for(auto* keyValuePairs : *assetPoolT6->m_key_value_pairs)
|
||||
for(auto* keyValuePairsEntry : *assetPoolT6->m_key_value_pairs)
|
||||
{
|
||||
for(int variableIndex = 0; variableIndex < keyValuePairs->m_asset->numVariables; variableIndex++)
|
||||
auto* keyValuePairs = keyValuePairsEntry->m_asset;
|
||||
for(int variableIndex = 0; variableIndex < keyValuePairs->numVariables; variableIndex++)
|
||||
{
|
||||
T6::KeyValuePair* variable = &keyValuePairs->m_asset->keyValuePairs[variableIndex];
|
||||
T6::KeyValuePair* variable = &keyValuePairs->keyValuePairs[variableIndex];
|
||||
|
||||
if(variable->namespaceHash == zoneNameHash && variable->keyHash == IPAK_READ_HASH)
|
||||
{
|
||||
@ -69,7 +92,53 @@ void ObjLoaderT6::UnloadContainersOfZone(Zone* zone)
|
||||
IPak::Repository.RemoveContainerReferences(zone);
|
||||
}
|
||||
|
||||
void ObjLoaderT6::LoadImageDataFromFile(T6::GfxImage* image, FileAPI::IFile* file, Zone* zone)
|
||||
{
|
||||
}
|
||||
|
||||
void ObjLoaderT6::LoadImageData(ISearchPath* searchPath, Zone* zone)
|
||||
{
|
||||
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->GetPools());
|
||||
|
||||
if (assetPoolT6->m_image != nullptr)
|
||||
{
|
||||
for (auto* imageEntry : *assetPoolT6->m_image)
|
||||
{
|
||||
auto* image = imageEntry->m_asset;
|
||||
|
||||
// TODO: Enable this when loadDef is no longer loaded into the temp block and never updated.
|
||||
// if(image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
std::string imageFileName = "images/" + std::string(image->name) + ".iwi";
|
||||
auto* filePathImage = searchPath->Open(imageFileName);
|
||||
if(filePathImage != nullptr && filePathImage->IsOpen())
|
||||
{
|
||||
LoadImageDataFromFile(image, filePathImage, zone);
|
||||
filePathImage->Close();
|
||||
delete filePathImage;
|
||||
}
|
||||
else if(image->streamedPartCount > 0)
|
||||
{
|
||||
for (auto* ipak : IPak::Repository)
|
||||
{
|
||||
auto* ipakEntry = ipak->GetEntryData(image->hash, image->streamedParts[0].hash);
|
||||
|
||||
if (ipakEntry != nullptr && ipakEntry->IsOpen())
|
||||
{
|
||||
LoadImageDataFromFile(image, ipakEntry, zone);
|
||||
ipakEntry->Close();
|
||||
delete ipakEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoaderT6::LoadObjDataForZone(ISearchPath* searchPath, Zone* zone)
|
||||
{
|
||||
// TODO
|
||||
LoadImageData(searchPath, zone);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "IObjLoader.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
class ObjLoaderT6 final : public IObjLoader
|
||||
{
|
||||
@ -11,6 +12,9 @@ class ObjLoaderT6 final : public IObjLoader
|
||||
|
||||
static void LoadIPakForZone(ISearchPath* searchPath, const std::string& ipakName, Zone* zone);
|
||||
|
||||
static void LoadImageDataFromFile(T6::GfxImage* image, FileAPI::IFile* file, Zone* zone);
|
||||
static void LoadImageData(ISearchPath* searchPath, Zone* zone);
|
||||
|
||||
public:
|
||||
bool SupportsZone(Zone* zone) override;
|
||||
|
||||
|
Reference in New Issue
Block a user