mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-07 21:38:01 -05:00
fix: doing wrong alignment on dynamic filling
This commit is contained in:
parent
af4abe49d3
commit
3338b007b4
@ -901,8 +901,10 @@ namespace
|
||||
{
|
||||
if (info && !info->m_has_matching_cross_platform_structure && StructureComputations(info).GetDynamicMember())
|
||||
{
|
||||
LINE("// Alloc first for alignment, then proceed to read as game does")
|
||||
LINEF("m_stream.Alloc({0});", def->GetAlignment())
|
||||
LINEF("const auto allocSize = LoadDynamicFill_{0}(m_stream.LoadWithFill(0));", MakeSafeTypeName(def))
|
||||
LINEF("*{0} = static_cast<{1}*>(m_stream.AllocOutOfBlock({2}, allocSize));", MakeTypePtrVarName(def), def->GetFullName(), def->GetAlignment())
|
||||
LINEF("*{0} = static_cast<{1}*>(m_stream.AllocOutOfBlock(0, allocSize));", MakeTypePtrVarName(def), def->GetFullName())
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1462,19 +1464,23 @@ namespace
|
||||
|
||||
if (preAllocDynamic)
|
||||
{
|
||||
LINEF("const auto allocSize = LoadDynamicFill_{0}(m_stream.LoadWithFill(0));", MakeSafeTypeName(member->m_type->m_definition))
|
||||
LINE_STARTF("{0} = static_cast<{1}{2}*>(m_stream.AllocOutOfBlock(", MakeMemberAccess(info, member, modifier), typeDecl, followingReferences)
|
||||
|
||||
LINE("// Alloc first for alignment, then proceed to read as game does")
|
||||
if (member->m_alloc_alignment)
|
||||
{
|
||||
LINE_MIDDLE(MakeEvaluation(member->m_alloc_alignment.get()))
|
||||
LINEF("m_stream.Alloc({0});", MakeEvaluation(member->m_alloc_alignment.get()))
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE_MIDDLEF("{0}", modifier.GetAlignment())
|
||||
LINEF("m_stream.Alloc({0});", modifier.GetAlignment())
|
||||
}
|
||||
|
||||
LINE_ENDF(", allocSize));", member->m_type->m_definition->GetFullName())
|
||||
LINEF("const auto allocSize = LoadDynamicFill_{0}(m_stream.LoadWithFill(0));", MakeSafeTypeName(member->m_type->m_definition))
|
||||
|
||||
// We do not align again, because we already did previously
|
||||
LINEF("{0} = static_cast<{1}{2}*>(m_stream.AllocOutOfBlock(0, allocSize));",
|
||||
MakeMemberAccess(info, member, modifier),
|
||||
typeDecl,
|
||||
followingReferences)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -164,6 +164,10 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
||||
{
|
||||
LoadXAsset(false);
|
||||
varXAsset++;
|
||||
|
||||
#ifdef DEBUG_OFFSETS
|
||||
m_stream.DebugOffsets(index);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
|
||||
ZoneStreamFillReadAccessor::ZoneStreamFillReadAccessor(
|
||||
@ -433,6 +435,25 @@ namespace
|
||||
return *m_pointer_redirect_lookup[redirectIndex];
|
||||
}
|
||||
|
||||
#ifdef DEBUG_OFFSETS
|
||||
void DebugOffsets(const size_t assetIndex) const override
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "Asset " << assetIndex;
|
||||
for (const auto& block : m_blocks)
|
||||
{
|
||||
if (block->m_type != XBlockType::BLOCK_TYPE_NORMAL)
|
||||
continue;
|
||||
|
||||
ss << " " << m_block_offsets[block->m_index];
|
||||
}
|
||||
|
||||
ss << "\n";
|
||||
std::cout << ss.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
void LoadDataFromBlock(const XBlock& block, void* dst, const size_t size)
|
||||
{
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#define DEBUG_OFFSETS 1
|
||||
|
||||
class ZoneStreamFillReadAccessor
|
||||
{
|
||||
public:
|
||||
@ -170,6 +172,10 @@ public:
|
||||
return static_cast<T*>(ConvertOffsetToAliasLookup(static_cast<const void*>(offset)));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_OFFSETS
|
||||
virtual void DebugOffsets(size_t assetIndex) const = 0;
|
||||
#endif
|
||||
|
||||
static std::unique_ptr<ZoneInputStream> Create(
|
||||
unsigned pointerBitCount, unsigned blockBitCount, std::vector<XBlock*>& blocks, block_t insertBlock, ILoadingStream& stream, MemoryManager& memory);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user