2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-25 13:51:58 +00:00

refactor: update T5 loading code for x64 support

This commit is contained in:
Jan
2025-06-23 18:22:28 +01:00
parent def9da6ae5
commit 1736f38d78
2 changed files with 44 additions and 10 deletions

View File

@ -41,6 +41,7 @@ using namespace T5;
ContentLoader::ContentLoader(Zone& zone, ZoneInputStream& stream)
: ContentLoaderBase(zone, stream),
varXAssetList(nullptr),
varXAsset(nullptr),
varScriptStringList(nullptr)
{
@ -48,16 +49,17 @@ ContentLoader::ContentLoader(Zone& zone, ZoneInputStream& stream)
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
m_stream.PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart)
m_stream.Load<ScriptStringList>(varScriptStringList);
assert(!atStreamStart);
if (varScriptStringList->strings != nullptr)
{
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
#ifdef ARCH_x86
varScriptStringList->strings = m_stream.Alloc<const char*>(4);
#else
varScriptStringList->strings = m_stream.AllocOutOfBlock<const char*>(4, varScriptStringList->count);
#endif
varXString = varScriptStringList->strings;
LoadXStringArray(true, varScriptStringList->count);
@ -65,8 +67,6 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
}
m_stream.PopBlock();
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
}
@ -138,21 +138,50 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
assert(varXAsset != nullptr);
if (atStreamStart)
{
#ifdef ARCH_x86
m_stream.Load<XAsset>(varXAsset, count);
#else
const auto fill = m_stream.LoadWithFill(8u * count);
for (size_t index = 0; index < count; index++)
{
fill.Fill(varXAsset[index].type, 8u * index);
fill.FillPtr(varXAsset[index].header.data, 8u * index + 4u);
m_stream.AddPointerLookup(&varXAsset[index].header.data, fill.BlockBuffer(8u * index + 4u));
}
#endif
}
for (size_t index = 0; index < count; index++)
{
LoadXAsset(false);
varXAsset++;
#ifdef DEBUG_OFFSETS
m_stream.DebugOffsets(index);
#endif
}
}
void ContentLoader::Load()
{
m_stream.PushBlock(XFILE_BLOCK_VIRTUAL);
XAssetList assetList{};
varXAssetList = &assetList;
#ifdef ARCH_x86
m_stream.LoadDataRaw(&assetList, sizeof(assetList));
#else
const auto fillAccessor = m_stream.LoadWithFill(16u);
varScriptStringList = &varXAssetList->stringList;
fillAccessor.Fill(varScriptStringList->count, 0u);
fillAccessor.FillPtr(varScriptStringList->strings, 4u);
fillAccessor.Fill(varXAssetList->assetCount, 8u);
fillAccessor.FillPtr(varXAssetList->assets, 12u);
#endif
m_stream.PushBlock(XFILE_BLOCK_VIRTUAL);
varScriptStringList = &assetList.stringList;
LoadScriptStringList(false);
@ -161,7 +190,11 @@ void ContentLoader::Load()
{
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
#ifdef ARCH_x86
assetList.assets = m_stream.Alloc<XAsset>(4);
#else
assetList.assets = m_stream.AllocOutOfBlock<XAsset>(4, assetList.assetCount);
#endif
varXAsset = assetList.assets;
LoadXAssetArray(true, assetList.assetCount);
}

View File

@ -18,6 +18,7 @@ namespace T5
void LoadXAsset(bool atStreamStart) const;
void LoadXAssetArray(bool atStreamStart, size_t count);
XAssetList* varXAssetList;
XAsset* varXAsset;
ScriptStringList* varScriptStringList;
};