From 752f760c3222193089a605a1824fe7cfdbb20577 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Thu, 23 May 2024 01:05:22 -0400 Subject: [PATCH] lyt_group matching --- config/SOUE01/splits.txt | 4 ++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + include/nw4r/lyt/lyt_drawInfo.h | 1 + include/nw4r/lyt/lyt_group.h | 30 +++++++------ include/nw4r/lyt/lyt_layout.h | 6 ++- src/nw4r/lyt/lyt_group.cpp | 76 +++++++++++++++++++++++++++++++++ src/nw4r/lyt/lyt_pane.cpp | 4 +- 8 files changed, 107 insertions(+), 17 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index fd9e79d7..5376ea1d 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -328,6 +328,10 @@ nw4r/lyt/lyt_pane.cpp: .sbss start:0x805766F0 end:0x805766F8 .sdata2 start:0x8057F220 end:0x8057F240 +nw4r/lyt/lyt_group.cpp: + .text start:0x80487EB0 end:0x8048820C + .data start:0x8056E4A8 end:0x8056E4B4 + nw4r/lyt/lyt_resourceAccessor.cpp: .text start:0x80492000 end:0x80492058 .data start:0x8056E7E0 end:0x8056E7F8 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 12d1ebfe..764dea4d 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37073,7 +37073,7 @@ lbl_8056E350 = .data:0x8056E350; // type:object size:0x38 lbl_8056E388 = .data:0x8056E388; // type:object size:0x60 lbl_8056E3E8 = .data:0x8056E3E8; // type:object size:0x46 scope:local data:string __vt__Q34nw4r3lyt4Pane = .data:0x8056E430; // type:object size:0x74 -lbl_8056E4A8 = .data:0x8056E4A8; // type:object size:0x10 +__vt__Q34nw4r3lyt5Group = .data:0x8056E4A8; // type:object size:0xC lbl_8056E4B8 = .data:0x8056E4B8; // type:object size:0x40 lbl_8056E4F8 = .data:0x8056E4F8; // type:object size:0x78 lbl_8056E570 = .data:0x8056E570; // type:object size:0x88 diff --git a/configure.py b/configure.py index c46c9ec8..7d5a6fdb 100644 --- a/configure.py +++ b/configure.py @@ -354,6 +354,7 @@ config.libs = [ [ Object(Matching, "nw4r/lyt/lyt_init.cpp"), Object(Matching, "nw4r/lyt/lyt_pane.cpp"), + Object(Matching, "nw4r/lyt/lyt_group.cpp"), Object(Matching, "nw4r/lyt/lyt_resourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_arcResourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_common.cpp"), diff --git a/include/nw4r/lyt/lyt_drawInfo.h b/include/nw4r/lyt/lyt_drawInfo.h index 8aafd6e9..a3cc03b9 100644 --- a/include/nw4r/lyt/lyt_drawInfo.h +++ b/include/nw4r/lyt/lyt_drawInfo.h @@ -12,6 +12,7 @@ struct DrawInfo { bool isYAxisUp() const { // NYI + return false; } // field accessors const math::VEC2 &GetLocationAdjustScale() const { diff --git a/include/nw4r/lyt/lyt_group.h b/include/nw4r/lyt/lyt_group.h index b12a8665..71f429b2 100644 --- a/include/nw4r/lyt/lyt_group.h +++ b/include/nw4r/lyt/lyt_group.h @@ -9,37 +9,39 @@ namespace nw4r { namespace lyt { namespace res { struct Group { - char UNK_0x0[0x8]; - char mName[NW4R_RES_NAME_SIZE]; // at 0x8 - u16 SHORT_0x18; + DataBlockHeader blockHeader; // at 0x00 "grp1" + char mName[NW4R_RES_NAME_SIZE]; // at 0x08 + u16 paneNum; // at 0x18 + u16 padding; // at 0x1A }; } // namespace res namespace detail { struct PaneLink { - ut::LinkListNode mNode; // at 0x0 - Pane *PANE_0x8; + ut::LinkListNode mLink; // at 0x0 + Pane *mTarget; // at 0x08 }; } // namespace detail struct Group { - Group(const res::Group *, Pane *); + Group(const res::Group *pResGroup, Pane *pRootPane); virtual ~Group(); - void AppendPane(Pane *); + void AppendPane(Pane *pPane); void Init(); - ut::LinkListNode mNode; // at 0x4 - ut::LinkList mPaneList; // at 0xC - char mName[NW4R_RES_NAME_SIZE]; // at 0x18 - bool mIsUserAllocated; // at 0x29 + ut::LinkListNode mLink; // at 0x04 + ut::LinkList mPaneListLink; // at 0x0C + char mName[NW4R_RES_NAME_SIZE + 1]; // at 0x18 + bool mbUserAllocated; // at 0x29 + u8 mPadding[2]; // at 0x2A }; struct GroupContainer { ~GroupContainer(); - void AppendGroup(Group *); - Group *FindGroupByName(const char *); + void AppendGroup(Group *pGroup); + Group *FindGroupByName(const char *findName); - ut::LinkList mGroups; // at 0x4 + ut::LinkList mGroupList; // at 0x4 }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 8bd38837..87ce0f67 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -50,7 +50,11 @@ struct Layout { template static T *NewObj() { T *obj = (T *)AllocMemory(sizeof(T)); - return new (obj) T(); + if (obj) { + return new (obj) T(); + } else { + return nullptr; + } } static MEMAllocator *mspAllocator; diff --git a/src/nw4r/lyt/lyt_group.cpp b/src/nw4r/lyt/lyt_group.cpp index e69de29b..493c25fc 100644 --- a/src/nw4r/lyt/lyt_group.cpp +++ b/src/nw4r/lyt/lyt_group.cpp @@ -0,0 +1,76 @@ +#include +#include + +namespace nw4r { + +namespace lyt { + +// __ct__Q34nw4r3lyt5GroupFPCQ44nw4r3lyt3res5GroupPQ34nw4r3lyt4Pane +Group::Group(const res::Group *pResGroup, Pane *pRootPane) : mLink(), mPaneListLink() { + Init(); + strncpy(this->mName, pResGroup->mName, NW4R_RES_NAME_SIZE); + this->mName[NW4R_RES_NAME_SIZE] = '\0'; + const char *paneNameBase = (char *)(&pResGroup[1]); + for (int i = 0; i < pResGroup->paneNum; i++) { + Pane *pFindPane = pRootPane->FindPaneByName(paneNameBase + i * NW4R_RES_NAME_SIZE, true); + if (pFindPane) { + AppendPane(pFindPane); + } + } +} + +// Init__Q34nw4r3lyt5GroupFv +void Group::Init() { + this->mbUserAllocated = false; +} + +// __dt__Q34nw4r3lyt5GroupFv +Group::~Group() { + ut::LinkList::Iterator it = this->mPaneListLink.GetBeginIter(); + while (it != this->mPaneListLink.GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + this->mPaneListLink.Erase(currIt); + Layout::DeleteObj(&*currIt); + } +} + +// AppendPane__Q34nw4r3lyt5GroupFPQ34nw4r3lyt4Pane +void Group::AppendPane(Pane *pPane) { + detail::PaneLink *pPaneLink = Layout::NewObj(); + if (pPaneLink) { + pPaneLink->mTarget = pPane; + this->mPaneListLink.PushBack(pPaneLink); + } +} + +//__dt__Q34nw4r3lyt14GroupContainerFv +GroupContainer::~GroupContainer() { + ut::LinkList::Iterator it = this->mGroupList.GetBeginIter(); + while (it != this->mGroupList.GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + this->mGroupList.Erase(currIt); + if (!currIt->mbUserAllocated) { + Layout::DeleteObj(&*currIt); + } + } +} + +// AppendGroup__Q34nw4r3lyt14GroupContainerFPQ34nw4r3lyt5Group +void GroupContainer::AppendGroup(Group *pGroup) { + this->mGroupList.PushBack(pGroup); +} + +// FindGroupByName__Q34nw4r3lyt14GroupContainerFPCc +Group *GroupContainer::FindGroupByName(const char *findName) { + for (ut::LinkList::Iterator it = this->mGroupList.GetBeginIter(); it != this->mGroupList.GetEndIter(); + it++) { + if (detail::EqualsResName(it->mName, findName)) { + return &*it; + } + } + return nullptr; +} + +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index 0b60a834..043beb87 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -28,13 +28,13 @@ PaneBase::~PaneBase() {} NW4R_UT_RTTI_DEF_BASE(Pane); -// 80486a70 // __ct__Q34nw4r3lyt4PaneFv // __dt__Q34nw4r2ut38LinkListFv // __dt__Q34nw4r2ut28LinkListFv +// 80486a70 // __ct__Q34nw4r3lyt4PaneFPCQ44nw4r3lyt3res4Pane Pane::Pane(const res::Pane *pBlock) : mChildList(), mAnimList(), mSize() { this->mpParent = nullptr; @@ -205,6 +205,8 @@ Material *Pane::FindMaterialByName(const char *findName, bool bRecursive) { } // CalculateMtx__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +// Matches for SS, applying the rotation and scale seems to be different accross versions. +// Also look out for the Bottom CalculateMtxChild section. In other version this is actually seperated differently void Pane::CalculateMtx(const DrawInfo &drawInfo) { if (!IsVisible() && !drawInfo.IsInvisiblePaneCalculateMtx()) { return;