mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
more t5 stuffs
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
#include "AssetLoaderLocalizeEntry.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Localize/LocalizeCommon.h"
|
||||
#include "Parsing/LocalizeFile/LocalizeFileReader.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
XAssetInfoGeneric* AssetLoaderLocalizeEntry::LoadFromGlobalAssetPools(const std::string& assetName) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* AssetLoaderLocalizeEntry::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AssetLoaderLocalizeEntry::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderLocalizeEntry::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
std::string fileName;
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << LocalizeCommon::GetNameOfLanguage(zone->m_language) << "/localizedstrings/" << assetName << ".str";
|
||||
fileName = str.str();
|
||||
}
|
||||
|
||||
const auto file = searchPath->Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language);
|
||||
const auto localizeEntries = reader.ReadLocalizeFile();
|
||||
|
||||
for (const auto& entry : localizeEntries)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, entry.m_key, localizeEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Game/T5/T5.h"
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class AssetLoaderLocalizeEntry final : public BasicAssetLoader<ASSET_TYPE_LOCALIZE_ENTRY, LocalizeEntry>
|
||||
{
|
||||
public:
|
||||
_NODISCARD XAssetInfoGeneric* LoadFromGlobalAssetPools(const std::string& assetName) const override;
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
#include "AssetLoaderRawFile.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
void* AssetLoaderRawFile::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* rawFile = memory->Create<RawFile>();
|
||||
memset(rawFile, 0, sizeof(RawFile));
|
||||
rawFile->name = memory->Dup(assetName.c_str());
|
||||
return rawFile;
|
||||
}
|
||||
|
||||
bool AssetLoaderRawFile::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderRawFile::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto file = searchPath->Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
auto* rawFile = memory->Create<RawFile>();
|
||||
rawFile->name = memory->Dup(assetName.c_str());
|
||||
rawFile->len = static_cast<int>(file.m_length);
|
||||
|
||||
auto* fileBuffer = static_cast<char*>(memory->Alloc(static_cast<size_t>(file.m_length + 1)));
|
||||
file.m_stream->read(fileBuffer, file.m_length);
|
||||
if (file.m_stream->gcount() != file.m_length)
|
||||
return false;
|
||||
fileBuffer[rawFile->len] = '\0';
|
||||
|
||||
rawFile->buffer = fileBuffer;
|
||||
manager->AddAsset(ASSET_TYPE_RAWFILE, assetName, rawFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "Game/T5/T5.h"
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class AssetLoaderRawFile final : public BasicAssetLoader<ASSET_TYPE_RAWFILE, RawFile>
|
||||
{
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
#include "AssetLoaderStringTable.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/T5/CommonT5.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
void* AssetLoaderStringTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* stringTable = memory->Create<StringTable>();
|
||||
memset(stringTable, 0, sizeof(StringTable));
|
||||
stringTable->name = memory->Dup(assetName.c_str());
|
||||
return stringTable;
|
||||
}
|
||||
|
||||
bool AssetLoaderStringTable::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderStringTable::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto file = searchPath->Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
auto* stringTable = memory->Create<StringTable>();
|
||||
stringTable->name = memory->Dup(assetName.c_str());
|
||||
|
||||
std::vector<std::vector<std::string>> csvLines;
|
||||
std::vector<std::string> currentLine;
|
||||
auto maxCols = 0u;
|
||||
const CsvInputStream csv(*file.m_stream);
|
||||
|
||||
while (csv.NextRow(currentLine))
|
||||
{
|
||||
if (currentLine.size() > maxCols)
|
||||
maxCols = currentLine.size();
|
||||
csvLines.emplace_back(std::move(currentLine));
|
||||
}
|
||||
|
||||
stringTable->columnCount = maxCols;
|
||||
stringTable->rowCount = csvLines.size();
|
||||
const auto cellCount = static_cast<unsigned>(stringTable->rowCount) * static_cast<unsigned>(stringTable->columnCount);
|
||||
|
||||
if (cellCount)
|
||||
{
|
||||
stringTable->values = static_cast<StringTableCell*>(memory->Alloc(sizeof(StringTableCell) * cellCount));
|
||||
stringTable->cellIndex = static_cast<int16_t*>(memory->Alloc(sizeof(int16_t) * cellCount));
|
||||
|
||||
for (auto c = 0u; c < cellCount; c++)
|
||||
stringTable->cellIndex[c] = static_cast<int16_t>(c);
|
||||
|
||||
for (auto row = 0u; row < csvLines.size(); row++)
|
||||
{
|
||||
const auto& rowValues = csvLines[row];
|
||||
for (auto col = 0u; col < maxCols; col++)
|
||||
{
|
||||
auto& cell = stringTable->values[row * maxCols + col];
|
||||
if (col >= rowValues.size() || rowValues[col].empty())
|
||||
cell.string = "";
|
||||
else
|
||||
cell.string = memory->Dup(rowValues[col].c_str());
|
||||
|
||||
cell.hash = CommonT5::Com_HashString(cell.string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::sort(&stringTable->cellIndex[0], &stringTable->cellIndex[cellCount - 1], [stringTable, maxCols](const int16_t a, const int16_t b)
|
||||
{
|
||||
auto compareResult = stringTable->values[a].hash - stringTable->values[b].hash;
|
||||
if (compareResult == 0)
|
||||
compareResult = a % maxCols - b % maxCols;
|
||||
return compareResult < 0;
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
stringTable->values = nullptr;
|
||||
stringTable->cellIndex = nullptr;
|
||||
}
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_STRINGTABLE, assetName, stringTable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "Game/T5/T5.h"
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class AssetLoaderStringTable final : public BasicAssetLoader<ASSET_TYPE_STRINGTABLE, StringTable>
|
||||
{
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,161 @@
|
||||
#include "ObjLoaderT5.h"
|
||||
|
||||
#include "Game/T5/GameT5.h"
|
||||
#include "Game/T5/GameAssetPoolT5.h"
|
||||
#include "ObjContainer/IPak/IPak.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
||||
#include "AssetLoaders/AssetLoaderRawFile.h"
|
||||
#include "AssetLoaders/AssetLoaderStringTable.h"
|
||||
#include "AssetLoading/AssetLoadingManager.h"
|
||||
#include "Image/Texture.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
ObjLoader::ObjLoader()
|
||||
{
|
||||
#define REGISTER_ASSET_LOADER(t) {auto l = std::make_unique<t>(); m_asset_loaders_by_type[l->GetHandlingAssetType()] = std::move(l);}
|
||||
#define BASIC_LOADER(assetType, assetClass) BasicAssetLoader<assetType, assetClass>
|
||||
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_PHYSPRESET, PhysPreset))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XANIMPARTS, XAnimParts))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XMODEL, XModel))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MATERIAL, Material))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_IMAGE, GfxImage))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND, snd_alias_list_t))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND_PATCH, SndPatch))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_CLIPMAP, clipMap_t))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_CLIPMAP_PVS, clipMap_t))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_COMWORLD, ComWorld))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GAMEWORLD_SP, GameWorldSp))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GAMEWORLD_MP, GameWorldMp))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MAP_ENTS, MapEnts))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GFXWORLD, GfxWorld))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_LIGHT_DEF, GfxLightDef))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FONT, Font_s))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MENULIST, MenuList))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MENU, menuDef_t))
|
||||
REGISTER_ASSET_LOADER(AssetLoaderLocalizeEntry)
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_WEAPON, WeaponDef))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SNDDRIVER_GLOBALS, SndDriverGlobals))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FX, FxEffectDef))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_IMPACT_FX, FxImpactTable))
|
||||
REGISTER_ASSET_LOADER(AssetLoaderRawFile)
|
||||
REGISTER_ASSET_LOADER(AssetLoaderStringTable)
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_PACK_INDEX, PackIndex))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XGLOBALS, XGlobals))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_DDL, ddlRoot_t))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GLASSES, Glasses))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_EMBLEMSET, EmblemSet))
|
||||
|
||||
#undef BASIC_LOADER
|
||||
#undef REGISTER_ASSET_LOADER
|
||||
}
|
||||
|
||||
bool ObjLoader::SupportsZone(Zone* zone) const
|
||||
{
|
||||
return zone->m_game == &g_GameT5;
|
||||
}
|
||||
|
||||
bool ObjLoader::IsMpZone(Zone* zone)
|
||||
{
|
||||
return zone->m_name.compare(0, 3, "mp_") == 0
|
||||
|| zone->m_name.compare(zone->m_name.length() - 3, 3, "_mp") == 0;
|
||||
}
|
||||
|
||||
bool ObjLoader::IsZmZone(Zone* zone)
|
||||
{
|
||||
return zone->m_name.compare(0, 3, "zm_") == 0
|
||||
|| zone->m_name.compare(zone->m_name.length() - 3, 3, "_zm") == 0;
|
||||
}
|
||||
|
||||
void ObjLoader::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone) const
|
||||
{
|
||||
}
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone* zone) const
|
||||
{
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
|
||||
{
|
||||
// TODO: Load Texture from LoadDef here
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone)
|
||||
{
|
||||
Texture* loadedTexture = nullptr;
|
||||
IwiLoader loader(zone->GetMemory());
|
||||
|
||||
const auto imageFileName = "images/" + std::string(image->name) + ".iwi";
|
||||
|
||||
{
|
||||
const auto filePathImage = searchPath->Open(imageFileName);
|
||||
if (filePathImage.IsOpen())
|
||||
{
|
||||
loadedTexture = loader.LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
{
|
||||
image->texture.texture = loadedTexture;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
|
||||
const auto textureMipCount = loadedTexture->GetMipMapCount();
|
||||
for (auto mipLevel = 0; mipLevel < textureMipCount; mipLevel++)
|
||||
image->cardMemory.platform[0] += static_cast<int>(loadedTexture->GetSizeOfMipLevel(mipLevel) * loadedTexture->GetFaceCount());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not find data for image \"%s\"\n", image->name);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone)
|
||||
{
|
||||
auto* assetPool = dynamic_cast<GameAssetPoolT5*>(zone->m_pools.get());
|
||||
|
||||
if (assetPool && assetPool->m_image != nullptr)
|
||||
{
|
||||
for (auto* imageEntry : *assetPool->m_image)
|
||||
{
|
||||
auto* image = imageEntry->Asset();
|
||||
|
||||
if (image->cardMemory.platform[0] > 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadObjDataForZone(ISearchPath* searchPath, Zone* zone) const
|
||||
{
|
||||
LoadImageData(searchPath, zone);
|
||||
}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext* context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, *context);
|
||||
return assetLoadingManager.LoadAssetFromLoader(assetType, assetName);
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "IObjLoader.h"
|
||||
#include "AssetLoading/IAssetLoader.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Game/T5/T5.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class ObjLoader final : public IObjLoader
|
||||
{
|
||||
std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>> m_asset_loaders_by_type;
|
||||
|
||||
static void LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone);
|
||||
static void LoadImageFromLoadDef(GfxImage* image, Zone* zone);
|
||||
static void LoadImageData(ISearchPath* searchPath, Zone* zone);
|
||||
|
||||
static bool IsMpZone(Zone* zone);
|
||||
static bool IsZmZone(Zone* zone);
|
||||
|
||||
public:
|
||||
ObjLoader();
|
||||
|
||||
bool SupportsZone(Zone* zone) const override;
|
||||
|
||||
void LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone) const override;
|
||||
void UnloadContainersOfZone(Zone* zone) const override;
|
||||
|
||||
void LoadObjDataForZone(ISearchPath* searchPath, Zone* zone) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext* context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user