2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-19 15:01:49 +00:00

fix: filling union members that are not supposed to be written

* This causes some pointers to be partially overwritten when filling in the wrong order as well
This commit is contained in:
Jan Laupetin
2026-01-14 22:14:43 +00:00
parent 9f559fdcd0
commit 00546740e4
15 changed files with 72 additions and 69 deletions

View File

@@ -2594,8 +2594,8 @@ namespace IW3
union entryInternalData union entryInternalData
{ {
int op;
Operand operand; Operand operand;
int op;
}; };
enum expressionEntryType : int enum expressionEntryType : int

View File

@@ -2044,8 +2044,8 @@ namespace IW4
union entryInternalData union entryInternalData
{ {
int op;
Operand operand; Operand operand;
int op;
}; };
enum expressionEntryType : int enum expressionEntryType : int

View File

@@ -2608,8 +2608,8 @@ namespace IW5
union entryInternalData union entryInternalData
{ {
int op;
Operand operand; Operand operand;
int op;
}; };
struct expressionEntry struct expressionEntry

View File

@@ -27,6 +27,11 @@ use MaterialShaderArgument;
set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST
|| type == MTL_ARG_LITERAL_PIXEL_CONST; || type == MTL_ARG_LITERAL_PIXEL_CONST;
set reusable u::literalConst; set reusable u::literalConst;
set condition u::codeConst type == MTL_ARG_CODE_VERTEX_CONST
|| type == MTL_ARG_CODE_PIXEL_CONST;
set condition u::codeSampler type == MTL_ARG_CODE_PIXEL_SAMPLER;
set condition u::nameHash type == MTL_ARG_MATERIAL_VERTEX_CONST
|| type == MTL_ARG_MATERIAL_PIXEL_CONST || type == MTL_ARG_MATERIAL_PIXEL_SAMPLER;
// MaterialPixelShader // MaterialPixelShader
set string MaterialPixelShader::name; set string MaterialPixelShader::name;

View File

@@ -24,3 +24,8 @@ use MaterialShaderArgument;
set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST
|| type == MTL_ARG_LITERAL_PIXEL_CONST; || type == MTL_ARG_LITERAL_PIXEL_CONST;
set reusable u::literalConst; set reusable u::literalConst;
set condition u::codeConst type == MTL_ARG_CODE_VERTEX_CONST
|| type == MTL_ARG_CODE_PIXEL_CONST;
set condition u::codeSampler type == MTL_ARG_CODE_PIXEL_SAMPLER;
set condition u::nameHash type == MTL_ARG_MATERIAL_VERTEX_CONST
|| type == MTL_ARG_MATERIAL_PIXEL_CONST || type == MTL_ARG_MATERIAL_PIXEL_SAMPLER;

View File

@@ -24,3 +24,8 @@ use MaterialShaderArgument;
set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST
|| type == MTL_ARG_LITERAL_PIXEL_CONST; || type == MTL_ARG_LITERAL_PIXEL_CONST;
set reusable u::literalConst; set reusable u::literalConst;
set condition u::codeConst type == MTL_ARG_CODE_VERTEX_CONST
|| type == MTL_ARG_CODE_PIXEL_CONST;
set condition u::codeSampler type == MTL_ARG_CODE_PIXEL_SAMPLER;
set condition u::nameHash type == MTL_ARG_MATERIAL_VERTEX_CONST
|| type == MTL_ARG_MATERIAL_PIXEL_CONST || type == MTL_ARG_MATERIAL_PIXEL_SAMPLER;

View File

@@ -47,3 +47,8 @@ use MaterialShaderArgument;
set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST
|| type == MTL_ARG_LITERAL_PIXEL_CONST; || type == MTL_ARG_LITERAL_PIXEL_CONST;
set reusable u::literalConst; set reusable u::literalConst;
set condition u::codeConst type == MTL_ARG_CODE_VERTEX_CONST
|| type == MTL_ARG_CODE_PIXEL_CONST;
set condition u::codeSampler type == MTL_ARG_CODE_PIXEL_SAMPLER;
set condition u::nameHash type == MTL_ARG_MATERIAL_VERTEX_CONST
|| type == MTL_ARG_MATERIAL_PIXEL_CONST || type == MTL_ARG_MATERIAL_PIXEL_SAMPLER;

View File

@@ -52,3 +52,8 @@ use MaterialShaderArgument;
set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST
|| type == MTL_ARG_LITERAL_PIXEL_CONST; || type == MTL_ARG_LITERAL_PIXEL_CONST;
set reusable u::literalConst; set reusable u::literalConst;
set condition u::codeConst type == MTL_ARG_CODE_VERTEX_CONST
|| type == MTL_ARG_CODE_PIXEL_CONST;
set condition u::codeSampler type == MTL_ARG_CODE_PIXEL_SAMPLER;
set condition u::nameHash type == MTL_ARG_MATERIAL_VERTEX_CONST
|| type == MTL_ARG_MATERIAL_PIXEL_CONST || type == MTL_ARG_MATERIAL_PIXEL_SAMPLER;

View File

@@ -189,15 +189,15 @@ bool MemberComputations::IsInRuntimeBlock() const
return m_info->m_fast_file_block != nullptr && m_info->m_fast_file_block->m_type == FastFileBlockType::RUNTIME; return m_info->m_fast_file_block != nullptr && m_info->m_fast_file_block->m_type == FastFileBlockType::RUNTIME;
} }
bool MemberComputations::IsFirstUsedMember() const bool MemberComputations::IsFirstUsedMember(const bool includeLeafs) const
{ {
const auto parentUsedMembers = StructureComputations(m_info->m_parent).GetUsedMembers(); const auto parentUsedMembers = StructureComputations(m_info->m_parent).GetUsedMembers(includeLeafs);
return !parentUsedMembers.empty() && parentUsedMembers[0] == m_info; return !parentUsedMembers.empty() && parentUsedMembers[0] == m_info;
} }
bool MemberComputations::IsLastUsedMember() const bool MemberComputations::IsLastUsedMember(const bool includeLeafs) const
{ {
const auto parentUsedMembers = StructureComputations(m_info->m_parent).GetUsedMembers(); const auto parentUsedMembers = StructureComputations(m_info->m_parent).GetUsedMembers(includeLeafs);
return !parentUsedMembers.empty() && parentUsedMembers[parentUsedMembers.size() - 1] == m_info; return !parentUsedMembers.empty() && parentUsedMembers[parentUsedMembers.size() - 1] == m_info;
} }

View File

@@ -25,8 +25,8 @@ public:
[[nodiscard]] bool IsNotInDefaultNormalBlock() const; [[nodiscard]] bool IsNotInDefaultNormalBlock() const;
[[nodiscard]] bool IsInTempBlock() const; [[nodiscard]] bool IsInTempBlock() const;
[[nodiscard]] bool IsInRuntimeBlock() const; [[nodiscard]] bool IsInRuntimeBlock() const;
[[nodiscard]] bool IsFirstUsedMember() const; [[nodiscard]] bool IsFirstUsedMember(bool includeLeafs) const;
[[nodiscard]] bool IsLastUsedMember() const; [[nodiscard]] bool IsLastUsedMember(bool includeLeafs) const;
[[nodiscard]] bool HasDynamicArraySize() const; [[nodiscard]] bool HasDynamicArraySize() const;
[[nodiscard]] bool IsDynamicMember() const; [[nodiscard]] bool IsDynamicMember() const;
[[nodiscard]] bool IsAfterPartialLoad() const; [[nodiscard]] bool IsAfterPartialLoad() const;

View File

@@ -38,7 +38,7 @@ bool StructureComputations::HasNonDynamicMember() const
return false; return false;
} }
std::vector<MemberInformation*> StructureComputations::GetUsedMembers() const std::vector<MemberInformation*> StructureComputations::GetUsedMembers(const bool includeLeafs) const
{ {
std::vector<MemberInformation*> members; std::vector<MemberInformation*> members;
@@ -54,7 +54,7 @@ std::vector<MemberInformation*> StructureComputations::GetUsedMembers() const
{ {
for (const auto& member : m_info->m_ordered_members) for (const auto& member : m_info->m_ordered_members)
{ {
if (!member->m_is_leaf && !MemberComputations(member.get()).ShouldIgnore()) if ((includeLeafs || !member->m_is_leaf) && !MemberComputations(member.get()).ShouldIgnore())
members.push_back(member.get()); members.push_back(member.get());
} }
} }

View File

@@ -10,7 +10,7 @@ public:
[[nodiscard]] bool IsAsset() const; [[nodiscard]] bool IsAsset() const;
[[nodiscard]] MemberInformation* GetDynamicMember() const; [[nodiscard]] MemberInformation* GetDynamicMember() const;
[[nodiscard]] bool HasNonDynamicMember() const; [[nodiscard]] bool HasNonDynamicMember() const;
[[nodiscard]] std::vector<MemberInformation*> GetUsedMembers() const; [[nodiscard]] std::vector<MemberInformation*> GetUsedMembers(bool includeLeafs) const;
[[nodiscard]] bool IsInTempBlock() const; [[nodiscard]] bool IsInTempBlock() const;
private: private:

View File

@@ -596,7 +596,7 @@ namespace
{ {
const MemberComputations computations(&member); const MemberComputations computations(&member);
if (computations.IsFirstUsedMember()) if (computations.IsFirstUsedMember(false))
{ {
if (member.m_condition) if (member.m_condition)
{ {
@@ -614,7 +614,7 @@ namespace
PrintFillStruct_Member(structInfo, member, DeclarationModifierComputations(&member), 0u); PrintFillStruct_Member(structInfo, member, DeclarationModifierComputations(&member), 0u);
} }
} }
else if (computations.IsLastUsedMember()) else if (computations.IsLastUsedMember(false))
{ {
if (member.m_condition) if (member.m_condition)
{ {
@@ -810,7 +810,7 @@ namespace
if (computations.ShouldIgnore()) if (computations.ShouldIgnore())
continue; continue;
if (computations.IsFirstUsedMember()) if (computations.IsFirstUsedMember(false))
{ {
LINE("") LINE("")
if (member->m_condition) if (member->m_condition)
@@ -829,7 +829,7 @@ namespace
PrintDynamicOversize_DynamicMember(info, *member); PrintDynamicOversize_DynamicMember(info, *member);
} }
} }
else if (computations.IsLastUsedMember()) else if (computations.IsLastUsedMember(false))
{ {
if (member->m_condition) if (member->m_condition)
{ {
@@ -1788,7 +1788,7 @@ namespace
{ {
const MemberComputations computations(member); const MemberComputations computations(member);
if (computations.IsFirstUsedMember()) if (computations.IsFirstUsedMember(false))
{ {
LINE("") LINE("")
if (member->m_condition) if (member->m_condition)
@@ -1807,7 +1807,7 @@ namespace
LoadMember_Reference(info, member, DeclarationModifierComputations(member)); LoadMember_Reference(info, member, DeclarationModifierComputations(member));
} }
} }
else if (computations.IsLastUsedMember()) else if (computations.IsLastUsedMember(false))
{ {
if (member->m_condition) if (member->m_condition)
{ {

View File

@@ -670,7 +670,7 @@ namespace
{ {
const MemberComputations computations(member); const MemberComputations computations(member);
if (computations.IsFirstUsedMember()) if (computations.IsFirstUsedMember(false))
{ {
LINE("") LINE("")
if (member->m_condition) if (member->m_condition)
@@ -689,7 +689,7 @@ namespace
MarkMember_Reference(info, member, DeclarationModifierComputations(member)); MarkMember_Reference(info, member, DeclarationModifierComputations(member));
} }
} }
else if (computations.IsLastUsedMember()) else if (computations.IsLastUsedMember(false))
{ {
if (member->m_condition) if (member->m_condition)
{ {

View File

@@ -1010,7 +1010,7 @@ namespace
{ {
const MemberComputations computations(member); const MemberComputations computations(member);
if (computations.IsFirstUsedMember()) if (computations.IsFirstUsedMember(false))
{ {
LINE("") LINE("")
if (member->m_condition) if (member->m_condition)
@@ -1029,7 +1029,7 @@ namespace
WriteMember_Reference(info, member, DeclarationModifierComputations(member)); WriteMember_Reference(info, member, DeclarationModifierComputations(member));
} }
} }
else if (computations.IsLastUsedMember()) else if (computations.IsLastUsedMember(false))
{ {
if (member->m_condition) if (member->m_condition)
{ {
@@ -1326,12 +1326,20 @@ namespace
} }
} }
static bool ShouldFillMember(const DeclarationModifierComputations& modifier)
{
return !modifier.HasPointerModifier();
}
// nestedBaseOffset: Base offset in case member is part of a nested anonymous sub-struct // nestedBaseOffset: Base offset in case member is part of a nested anonymous sub-struct
void PrintFillStruct_Member(const StructureInformation& structInfo, void PrintFillStruct_Member(const StructureInformation& structInfo,
const MemberInformation& memberInfo, const MemberInformation& memberInfo,
const DeclarationModifierComputations& modifier, const DeclarationModifierComputations& modifier,
const size_t nestedBaseOffset) const size_t nestedBaseOffset)
{ {
if (!ShouldFillMember(modifier))
return;
if (modifier.IsDynamicArray()) if (modifier.IsDynamicArray())
{ {
} }
@@ -1360,7 +1368,7 @@ namespace
{ {
const MemberComputations computations(&member); const MemberComputations computations(&member);
if (computations.IsFirstUsedMember()) if (computations.IsFirstUsedMember(true))
{ {
if (member.m_condition) if (member.m_condition)
{ {
@@ -1378,7 +1386,7 @@ namespace
PrintFillStruct_Member(structInfo, member, modifier, 0u); PrintFillStruct_Member(structInfo, member, modifier, 0u);
} }
} }
else if (computations.IsLastUsedMember()) else if (computations.IsLastUsedMember(true))
{ {
if (member.m_condition) if (member.m_condition)
{ {
@@ -1423,49 +1431,10 @@ namespace
} }
} }
static bool ShouldFillMember(const DeclarationModifierComputations& modifier)
{
return !modifier.HasPointerModifier();
}
void PrintFillStruct_Struct(const StructureInformation& info) void PrintFillStruct_Struct(const StructureInformation& info)
{ {
const auto* dynamicMember = StructureComputations(&info).GetDynamicMember(); const auto* dynamicMember = StructureComputations(&info).GetDynamicMember();
if (info.m_definition->GetType() == DataDefinitionType::UNION)
if (dynamicMember)
{
if (info.m_definition->GetType() == DataDefinitionType::UNION)
{
for (const auto& member : info.m_ordered_members)
{
const MemberComputations computations(member.get());
if (computations.ShouldIgnore())
continue;
DeclarationModifierComputations modifier(member.get());
if (!ShouldFillMember(modifier))
continue;
PrintFillStruct_Member_Condition_Union(info, *member, modifier);
}
}
else
{
for (const auto& member : info.m_ordered_members)
{
const MemberComputations computations(member.get());
if (computations.ShouldIgnore() || member.get() == dynamicMember)
continue;
DeclarationModifierComputations modifier(member.get());
if (!ShouldFillMember(modifier))
continue;
PrintFillStruct_Member(info, *member, modifier, 0u);
}
}
}
else
{ {
for (const auto& member : info.m_ordered_members) for (const auto& member : info.m_ordered_members)
{ {
@@ -1474,9 +1443,18 @@ namespace
continue; continue;
DeclarationModifierComputations modifier(member.get()); DeclarationModifierComputations modifier(member.get());
if (!ShouldFillMember(modifier)) PrintFillStruct_Member_Condition_Union(info, *member, modifier);
}
}
else
{
for (const auto& member : info.m_ordered_members)
{
const MemberComputations computations(member.get());
if (computations.ShouldIgnore() || member.get() == dynamicMember)
continue; continue;
DeclarationModifierComputations modifier(member.get());
PrintFillStruct_Member(info, *member, modifier, 0u); PrintFillStruct_Member(info, *member, modifier, 0u);
} }
} }