2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-25 05:41:53 +00:00

refactor: update IW3 loading code for x64 support

This commit is contained in:
Jan
2025-06-23 18:56:08 +01:00
parent 37e5e940b0
commit a9a8597323
2 changed files with 44 additions and 10 deletions

View File

@ -34,6 +34,7 @@ using namespace IW3;
ContentLoader::ContentLoader(Zone& zone, ZoneInputStream& stream)
: ContentLoaderBase(zone, stream),
varXAssetList(nullptr),
varXAsset(nullptr),
varScriptStringList(nullptr)
{
@ -41,16 +42,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);
@ -58,8 +60,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);
}
@ -125,21 +125,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);
@ -148,7 +177,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 IW3
void LoadXAsset(bool atStreamStart) const;
void LoadXAssetArray(bool atStreamStart, size_t count);
XAssetList* varXAssetList;
XAsset* varXAsset;
ScriptStringList* varScriptStringList;
};