This commit is contained in:
commit
8294be1b32
@ -1,5 +1,7 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
|
||||||
|
#define IW4X_IMG_VERSION "0"
|
||||||
|
|
||||||
namespace Assets
|
namespace Assets
|
||||||
{
|
{
|
||||||
void IGfxImage::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
void IGfxImage::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
@ -19,71 +21,90 @@ namespace Assets
|
|||||||
image->category = 0;
|
image->category = 0;
|
||||||
image->cardMemory = 0;
|
image->cardMemory = 0;
|
||||||
|
|
||||||
image->loadDef = builder->getAllocator()->allocate<Game::GfxImageLoadDef>();
|
const char* tempName = image->name;
|
||||||
if (!image->loadDef)
|
if (tempName[0] == '*') tempName++;
|
||||||
|
|
||||||
|
Components::FileSystem::File imageFile(fmt::sprintf("images/%s.iw4xImage", tempName));
|
||||||
|
if (imageFile.exists())
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
|
Utils::Stream::Reader reader(builder->getAllocator(), imageFile.getBuffer());
|
||||||
return;
|
|
||||||
|
if (reader.read<__int64>() != *reinterpret_cast<__int64*>("IW4xImg" IW4X_IMG_VERSION))
|
||||||
|
{
|
||||||
|
Components::Logger::Error(0, "Reading image '%s' failed, header is invalid!", name.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertSize(Game::MapType, 1);
|
||||||
|
image->mapType = reader.read<Game::MapType>();
|
||||||
|
image->semantic = reader.read<char>();
|
||||||
|
image->category = reader.read<char>();
|
||||||
|
|
||||||
|
image->dataLen1 = reader.read<int>();
|
||||||
|
image->dataLen2 = image->dataLen1;
|
||||||
|
|
||||||
|
image->loadDef = reinterpret_cast<Game::GfxImageLoadDef*>(reader.readArray<char>(image->dataLen1 + 16));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
char nameBuffer[MAX_PATH] = { 0 };
|
|
||||||
Components::Materials::FormatImagePath(nameBuffer, sizeof(nameBuffer), 0, 0, name.data());
|
|
||||||
Components::FileSystem::File iwi(nameBuffer);
|
|
||||||
|
|
||||||
if (!iwi.exists())
|
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Loading image '%s' failed!", iwi.getName().data());
|
char nameBuffer[MAX_PATH] = { 0 };
|
||||||
return;
|
Components::Materials::FormatImagePath(nameBuffer, sizeof(nameBuffer), 0, 0, name.data());
|
||||||
}
|
Components::FileSystem::File iwi(nameBuffer);
|
||||||
|
|
||||||
auto iwiBuffer = iwi.getBuffer();
|
if (!iwi.exists())
|
||||||
|
|
||||||
const Game::GfxImageFileHeader* iwiHeader = reinterpret_cast<const Game::GfxImageFileHeader*>(iwiBuffer.data());
|
|
||||||
|
|
||||||
image->mapType = Game::MAPTYPE_2D;
|
|
||||||
image->dataLen1 = iwiHeader->fileSizeForPicmip[0] - 32;
|
|
||||||
image->dataLen2 = iwiHeader->fileSizeForPicmip[0] - 32;
|
|
||||||
|
|
||||||
if (std::memcmp(iwiHeader->tag, "IWi", 3))
|
|
||||||
{
|
|
||||||
Components::Logger::Error("Image is not a valid IWi!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::memcpy(image->loadDef->dimensions, iwiHeader->dimensions, 6);
|
|
||||||
image->loadDef->flags = 0;
|
|
||||||
image->loadDef->levelCount = 0;
|
|
||||||
|
|
||||||
switch (iwiHeader->format)
|
|
||||||
{
|
|
||||||
case Game::IWI_COMPRESSION::IWI_ARGB:
|
|
||||||
{
|
{
|
||||||
image->loadDef->format = 21;
|
Components::Logger::Error("Loading image '%s' failed!", iwi.getName().data());
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Game::IWI_COMPRESSION::IWI_RGB8:
|
auto iwiBuffer = iwi.getBuffer();
|
||||||
|
|
||||||
|
const Game::GfxImageFileHeader* iwiHeader = reinterpret_cast<const Game::GfxImageFileHeader*>(iwiBuffer.data());
|
||||||
|
|
||||||
|
image->mapType = Game::MAPTYPE_2D;
|
||||||
|
image->dataLen1 = iwiHeader->fileSizeForPicmip[0] - 32;
|
||||||
|
image->dataLen2 = iwiHeader->fileSizeForPicmip[0] - 32;
|
||||||
|
|
||||||
|
if (std::memcmp(iwiHeader->tag, "IWi", 3) && iwiHeader->version == 8)
|
||||||
{
|
{
|
||||||
image->loadDef->format = 20;
|
Components::Logger::Error("Image is not a valid IWi!");
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Game::IWI_COMPRESSION::IWI_DXT1:
|
std::memcpy(image->loadDef->dimensions, iwiHeader->dimensions, 6);
|
||||||
{
|
image->loadDef->flags = 0;
|
||||||
image->loadDef->format = 0x31545844;
|
image->loadDef->levelCount = 0;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Game::IWI_COMPRESSION::IWI_DXT3:
|
switch (iwiHeader->format)
|
||||||
{
|
{
|
||||||
image->loadDef->format = 0x33545844;
|
case Game::IWI_COMPRESSION::IWI_ARGB:
|
||||||
break;
|
{
|
||||||
}
|
image->loadDef->format = 21;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Game::IWI_COMPRESSION::IWI_DXT5:
|
case Game::IWI_COMPRESSION::IWI_RGB8:
|
||||||
{
|
{
|
||||||
image->loadDef->format = 0x35545844;
|
image->loadDef->format = 20;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Game::IWI_COMPRESSION::IWI_DXT1:
|
||||||
|
{
|
||||||
|
image->loadDef->format = 0x31545844;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Game::IWI_COMPRESSION::IWI_DXT3:
|
||||||
|
{
|
||||||
|
image->loadDef->format = 0x33545844;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Game::IWI_COMPRESSION::IWI_DXT5:
|
||||||
|
{
|
||||||
|
image->loadDef->format = 0x35545844;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,10 @@ namespace Assets
|
|||||||
|
|
||||||
for (int j = 0; j < cell->portalCount; ++j)
|
for (int j = 0; j < cell->portalCount; ++j)
|
||||||
{
|
{
|
||||||
cell->portals[i].vertices = reader.readArray<Game::vec3_t>(cell->portals[i].vertexCount);
|
if (cell->portals[j].vertices)
|
||||||
|
{
|
||||||
|
cell->portals[j].vertices = reader.readArray<Game::vec3_t>(cell->portals[j].vertexCount & 0xFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user