mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
ObjLoading: Add basis for Iwi loading
This commit is contained in:
parent
589347ce08
commit
5bda400acb
@ -3,6 +3,8 @@
|
|||||||
#include "Game/T6/GameAssetPoolT6.h"
|
#include "Game/T6/GameAssetPoolT6.h"
|
||||||
#include "ObjContainer/IPak/IPak.h"
|
#include "ObjContainer/IPak/IPak.h"
|
||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
|
#include "Image/Texture.h"
|
||||||
|
#include "Image/IwiLoader.h"
|
||||||
|
|
||||||
const int ObjLoaderT6::IPAK_READ_HASH = Com_HashKey("ipak_read", 64);
|
const int ObjLoaderT6::IPAK_READ_HASH = Com_HashKey("ipak_read", 64);
|
||||||
const int ObjLoaderT6::GLOBAL_HASH = Com_HashKey("GLOBAL", 64);
|
const int ObjLoaderT6::GLOBAL_HASH = Com_HashKey("GLOBAL", 64);
|
||||||
@ -33,7 +35,7 @@ void ObjLoaderT6::LoadIPakForZone(ISearchPath* searchPath, const std::string& ip
|
|||||||
{
|
{
|
||||||
if(ObjLoading::Configuration.Verbose)
|
if(ObjLoading::Configuration.Verbose)
|
||||||
{
|
{
|
||||||
printf("Loading ipak '%s' for zone '%s'\n", ipakName.c_str(), zone->m_name.c_str());
|
printf("Trying to load ipak '%s' for zone '%s'\n", ipakName.c_str(), zone->m_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ipakFilename = ipakName + ".ipak";
|
const std::string ipakFilename = ipakName + ".ipak";
|
||||||
@ -46,6 +48,8 @@ void ObjLoaderT6::LoadIPakForZone(ISearchPath* searchPath, const std::string& ip
|
|||||||
if(ipak->Initialize())
|
if(ipak->Initialize())
|
||||||
{
|
{
|
||||||
IPak::Repository.AddContainer(ipak, zone);
|
IPak::Repository.AddContainer(ipak, zone);
|
||||||
|
|
||||||
|
printf("Found and loaded ipak '%s'.\n", ipakFilename.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -98,34 +102,27 @@ void ObjLoaderT6::UnloadContainersOfZone(Zone* zone)
|
|||||||
IPak::Repository.RemoveContainerReferences(zone);
|
IPak::Repository.RemoveContainerReferences(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjLoaderT6::LoadImageDataFromFile(T6::GfxImage* image, FileAPI::IFile* file, Zone* zone)
|
void ObjLoaderT6::LoadImageFromLoadDef(T6::GfxImage* image, Zone* zone)
|
||||||
{
|
{
|
||||||
|
// TODO: Load Texture from LoadDef here
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjLoaderT6::LoadImageData(ISearchPath* searchPath, Zone* zone)
|
void ObjLoaderT6::LoadImageFromIwi(T6::GfxImage* image, ISearchPath* searchPath, Zone* zone)
|
||||||
{
|
{
|
||||||
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->GetPools());
|
Texture* loadedTexture = nullptr;
|
||||||
|
IwiLoader loader(zone->GetMemory());
|
||||||
|
|
||||||
if (assetPoolT6->m_image != nullptr)
|
const std::string imageFileName = "images/" + std::string(image->name) + ".iwi";
|
||||||
{
|
|
||||||
for (auto* imageEntry : *assetPoolT6->m_image)
|
|
||||||
{
|
|
||||||
auto* image = imageEntry->m_asset;
|
|
||||||
|
|
||||||
if(image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string imageFileName = "images/" + std::string(image->name) + ".iwi";
|
|
||||||
auto* filePathImage = searchPath->Open(imageFileName);
|
auto* filePathImage = searchPath->Open(imageFileName);
|
||||||
if(filePathImage != nullptr && filePathImage->IsOpen())
|
|
||||||
|
if (filePathImage != nullptr && filePathImage->IsOpen())
|
||||||
{
|
{
|
||||||
LoadImageDataFromFile(image, filePathImage, zone);
|
loadedTexture = loader.LoadIwi(filePathImage);
|
||||||
|
|
||||||
filePathImage->Close();
|
filePathImage->Close();
|
||||||
delete filePathImage;
|
delete filePathImage;
|
||||||
}
|
}
|
||||||
else if(image->streamedPartCount > 0)
|
else if (image->streamedPartCount > 0)
|
||||||
{
|
{
|
||||||
for (auto* ipak : IPak::Repository)
|
for (auto* ipak : IPak::Repository)
|
||||||
{
|
{
|
||||||
@ -133,12 +130,53 @@ void ObjLoaderT6::LoadImageData(ISearchPath* searchPath, Zone* zone)
|
|||||||
|
|
||||||
if (ipakEntry != nullptr && ipakEntry->IsOpen())
|
if (ipakEntry != nullptr && ipakEntry->IsOpen())
|
||||||
{
|
{
|
||||||
LoadImageDataFromFile(image, ipakEntry, zone);
|
loadedTexture = loader.LoadIwi(ipakEntry);
|
||||||
|
|
||||||
ipakEntry->Close();
|
ipakEntry->Close();
|
||||||
delete ipakEntry;
|
delete ipakEntry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(loadedTexture != nullptr)
|
||||||
|
{
|
||||||
|
image->texture.texture = loadedTexture;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Could not find data for image \"%s\"\n", image->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjLoaderT6::LoadImageData(ISearchPath* searchPath, Zone* zone)
|
||||||
|
{
|
||||||
|
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->GetPools());
|
||||||
|
|
||||||
|
if (assetPoolT6 && assetPoolT6->m_image != nullptr)
|
||||||
|
{
|
||||||
|
for (auto* imageEntry : *assetPoolT6->m_image)
|
||||||
|
{
|
||||||
|
auto* image = imageEntry->m_asset;
|
||||||
|
|
||||||
|
if(image->loadedSize > 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not load linked assets
|
||||||
|
if(image->name && image->name[0] == ',')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
|
||||||
|
{
|
||||||
|
LoadImageFromLoadDef(image, zone);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadImageFromIwi(image, searchPath, zone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ class ObjLoaderT6 final : public IObjLoader
|
|||||||
|
|
||||||
static void LoadIPakForZone(ISearchPath* searchPath, const std::string& ipakName, Zone* zone);
|
static void LoadIPakForZone(ISearchPath* searchPath, const std::string& ipakName, Zone* zone);
|
||||||
|
|
||||||
static void LoadImageDataFromFile(T6::GfxImage* image, FileAPI::IFile* file, Zone* zone);
|
static void LoadImageFromIwiFile(T6::GfxImage* image, FileAPI::IFile* file, Zone* zone);
|
||||||
|
static void LoadImageFromIwi(T6::GfxImage* image, ISearchPath* searchPath, Zone* zone);
|
||||||
|
static void LoadImageFromLoadDef(T6::GfxImage* image, Zone* zone);
|
||||||
static void LoadImageData(ISearchPath* searchPath, Zone* zone);
|
static void LoadImageData(ISearchPath* searchPath, Zone* zone);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
24
src/ObjLoading/Image/IwiLoader.cpp
Normal file
24
src/ObjLoading/Image/IwiLoader.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "IwiLoader.h"
|
||||||
|
|
||||||
|
IwiLoader::IwiLoader(MemoryManager* memoryManager)
|
||||||
|
{
|
||||||
|
m_memory_manager = memoryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture* IwiLoader::LoadIwi(FileAPI::IFile* file)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
char tag[3];
|
||||||
|
char version;
|
||||||
|
} iwiHeaderMeta{};
|
||||||
|
|
||||||
|
if (file->Read(&iwiHeaderMeta, sizeof iwiHeaderMeta, 1) != 1)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
printf("Read IWI with version %i\n", iwiHeaderMeta.version);
|
||||||
|
|
||||||
|
// TODO: Read iwi based on version
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
15
src/ObjLoading/Image/IwiLoader.h
Normal file
15
src/ObjLoading/Image/IwiLoader.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Utils/FileAPI.h"
|
||||||
|
#include "Utils/MemoryManager.h"
|
||||||
|
#include "Image/Texture.h"
|
||||||
|
|
||||||
|
class IwiLoader
|
||||||
|
{
|
||||||
|
MemoryManager* m_memory_manager;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit IwiLoader(MemoryManager* memoryManager);
|
||||||
|
|
||||||
|
Texture* LoadIwi(FileAPI::IFile* file);
|
||||||
|
};
|
@ -168,7 +168,9 @@ public:
|
|||||||
{
|
{
|
||||||
if(entry.key.nameHash == nameHash && entry.key.dataHash == dataHash)
|
if(entry.key.nameHash == nameHash && entry.key.dataHash == dataHash)
|
||||||
{
|
{
|
||||||
|
// TODO: Implement ipak reader as IFile interface and use here
|
||||||
__asm nop;
|
__asm nop;
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user