mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-08 21:45:40 +00: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())
|
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("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
|
else
|
||||||
{
|
{
|
||||||
@ -1462,19 +1464,23 @@ namespace
|
|||||||
|
|
||||||
if (preAllocDynamic)
|
if (preAllocDynamic)
|
||||||
{
|
{
|
||||||
LINEF("const auto allocSize = LoadDynamicFill_{0}(m_stream.LoadWithFill(0));", MakeSafeTypeName(member->m_type->m_definition))
|
LINE("// Alloc first for alignment, then proceed to read as game does")
|
||||||
LINE_STARTF("{0} = static_cast<{1}{2}*>(m_stream.AllocOutOfBlock(", MakeMemberAccess(info, member, modifier), typeDecl, followingReferences)
|
|
||||||
|
|
||||||
if (member->m_alloc_alignment)
|
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
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -164,6 +164,10 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
|||||||
{
|
{
|
||||||
LoadXAsset(false);
|
LoadXAsset(false);
|
||||||
varXAsset++;
|
varXAsset++;
|
||||||
|
|
||||||
|
#ifdef DEBUG_OFFSETS
|
||||||
|
m_stream.DebugOffsets(index);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
ZoneStreamFillReadAccessor::ZoneStreamFillReadAccessor(
|
ZoneStreamFillReadAccessor::ZoneStreamFillReadAccessor(
|
||||||
@ -433,6 +435,25 @@ namespace
|
|||||||
return *m_pointer_redirect_lookup[redirectIndex];
|
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:
|
private:
|
||||||
void LoadDataFromBlock(const XBlock& block, void* dst, const size_t size)
|
void LoadDataFromBlock(const XBlock& block, void* dst, const size_t size)
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#define DEBUG_OFFSETS 1
|
||||||
|
|
||||||
class ZoneStreamFillReadAccessor
|
class ZoneStreamFillReadAccessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -170,6 +172,10 @@ public:
|
|||||||
return static_cast<T*>(ConvertOffsetToAliasLookup(static_cast<const void*>(offset)));
|
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(
|
static std::unique_ptr<ZoneInputStream> Create(
|
||||||
unsigned pointerBitCount, unsigned blockBitCount, std::vector<XBlock*>& blocks, block_t insertBlock, ILoadingStream& stream, MemoryManager& memory);
|
unsigned pointerBitCount, unsigned blockBitCount, std::vector<XBlock*>& blocks, block_t insertBlock, ILoadingStream& stream, MemoryManager& memory);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user