mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-25 13:51:58 +00:00
refactor: update IW3 loading code for x64 support
This commit is contained in:
@ -34,6 +34,7 @@ using namespace IW3;
|
|||||||
|
|
||||||
ContentLoader::ContentLoader(Zone& zone, ZoneInputStream& stream)
|
ContentLoader::ContentLoader(Zone& zone, ZoneInputStream& stream)
|
||||||
: ContentLoaderBase(zone, stream),
|
: ContentLoaderBase(zone, stream),
|
||||||
|
varXAssetList(nullptr),
|
||||||
varXAsset(nullptr),
|
varXAsset(nullptr),
|
||||||
varScriptStringList(nullptr)
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
@ -41,16 +42,17 @@ ContentLoader::ContentLoader(Zone& zone, ZoneInputStream& stream)
|
|||||||
|
|
||||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||||
{
|
{
|
||||||
m_stream.PushBlock(XFILE_BLOCK_VIRTUAL);
|
assert(!atStreamStart);
|
||||||
|
|
||||||
if (atStreamStart)
|
|
||||||
m_stream.Load<ScriptStringList>(varScriptStringList);
|
|
||||||
|
|
||||||
if (varScriptStringList->strings != nullptr)
|
if (varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
|
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;
|
varXString = varScriptStringList->strings;
|
||||||
LoadXStringArray(true, varScriptStringList->count);
|
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_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);
|
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);
|
assert(varXAsset != nullptr);
|
||||||
|
|
||||||
if (atStreamStart)
|
if (atStreamStart)
|
||||||
|
{
|
||||||
|
#ifdef ARCH_x86
|
||||||
m_stream.Load<XAsset>(varXAsset, count);
|
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++)
|
for (size_t index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
LoadXAsset(false);
|
LoadXAsset(false);
|
||||||
varXAsset++;
|
varXAsset++;
|
||||||
|
|
||||||
|
#ifdef DEBUG_OFFSETS
|
||||||
|
m_stream.DebugOffsets(index);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::Load()
|
void ContentLoader::Load()
|
||||||
{
|
{
|
||||||
m_stream.PushBlock(XFILE_BLOCK_VIRTUAL);
|
|
||||||
|
|
||||||
XAssetList assetList{};
|
XAssetList assetList{};
|
||||||
|
varXAssetList = &assetList;
|
||||||
|
|
||||||
|
#ifdef ARCH_x86
|
||||||
m_stream.LoadDataRaw(&assetList, sizeof(assetList));
|
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;
|
varScriptStringList = &assetList.stringList;
|
||||||
LoadScriptStringList(false);
|
LoadScriptStringList(false);
|
||||||
@ -148,7 +177,11 @@ void ContentLoader::Load()
|
|||||||
{
|
{
|
||||||
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
|
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;
|
varXAsset = assetList.assets;
|
||||||
LoadXAssetArray(true, assetList.assetCount);
|
LoadXAssetArray(true, assetList.assetCount);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace IW3
|
|||||||
void LoadXAsset(bool atStreamStart) const;
|
void LoadXAsset(bool atStreamStart) const;
|
||||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
|
XAssetList* varXAssetList;
|
||||||
XAsset* varXAsset;
|
XAsset* varXAsset;
|
||||||
ScriptStringList* varScriptStringList;
|
ScriptStringList* varScriptStringList;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user