From afbcb57c6270464d781206c562f680b91b4660f7 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Wed, 5 Jun 2024 23:05:18 -0400 Subject: [PATCH] lyt_material OK - Thanks robojumper for pointing out weak function order from header uses --- config/SOUE01/config.yml | 1 + configure.py | 2 +- include/nw4r/lyt/lyt_material.h | 38 ++++++++++ src/nw4r/lyt/lyt_material.cpp | 128 ++++++++++++++++---------------- 4 files changed, 104 insertions(+), 65 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 74626e27..6b4d9eb2 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -20,6 +20,7 @@ force_active: [ "GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc", "GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo", "SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font", + "GetTexMapAry__Q34nw4r3lyt8MaterialCFv", ] # modules: diff --git a/configure.py b/configure.py index 8f362118..8c4247ed 100644 --- a/configure.py +++ b/configure.py @@ -360,7 +360,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_textBox.cpp"), Object(Matching, "nw4r/lyt/lyt_window.cpp"), Object(Matching, "nw4r/lyt/lyt_bounding.cpp"), - Object(NonMatching, "nw4r/lyt/lyt_material.cpp"), + Object(Matching, "nw4r/lyt/lyt_material.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_material.h b/include/nw4r/lyt/lyt_material.h index 05a574f1..3a1d4dce 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -132,6 +132,44 @@ public: GetTexCoordGenAry()[idx] = value; } + // Begin Functions not found in DWARF, but assumed from BBA map and required for weak func ordering + void SetTevColor(u32 idx, const GXColorS10 &color) { + mTevCols[idx] = color; + } + + void SetAlphaCompare(const AlphaCompare &alphaComp) { + *GetAlphaComparePtr() = alphaComp; + } + + void SetChanControl(u32 idx, const ChanCtrl &chanCtrl) { + GetChanCtrlAry()[idx] = chanCtrl; + } + + void SetTevKColor(u32 idx, const ut::Color &color) { + mTevKCols[idx] = color; + } + + void SetTevSwapMode(u32 idx, const TevSwapMode &tevSwapMode) { + GetTevSwapAry()[idx] = tevSwapMode; + } + + void SetTexSRT(u32 idx, const TexSRT &texSRT) { + GetTexSRTAry()[idx] = texSRT; + } + + void SetIndirectStage(u32 idx, const IndirectStage &indStage) { + GetIndirectStageAry()[idx] = indStage; + } + + void SetBlendMode(const BlendMode &blendMode) { + *GetBlendModePtr() = blendMode; + } + + void SetTevStage(u32 idx, const TevStage &tevStage) { + GetTevStageAry()[idx] = tevStage; + } + // End Functions not found in DWARF, but assumed from BBA map and required for weak func ordering + virtual ~Material(); // at 0x08 virtual bool SetupGX(bool bModVtxCol, u8 alpha); // at 0x0C virtual void BindAnimation(AnimTransform *pAnimTrans); // at 0x10 diff --git a/src/nw4r/lyt/lyt_material.cpp b/src/nw4r/lyt/lyt_material.cpp index 82525b90..cf8fe4df 100644 --- a/src/nw4r/lyt/lyt_material.cpp +++ b/src/nw4r/lyt/lyt_material.cpp @@ -275,78 +275,78 @@ Material::Material(const res::Material *pRes, const ResBlockSet &resBlockSet) : } SetTextureNum(di); } - } - TexSRT *texSRTs = GetTexSRTAry(); - for (int i = 0; i < texSRTNum; i++) { - texSRTs[i].translate = pResTexSRTs[i].translate; - texSRTs[i].rotate = pResTexSRTs[i].rotate; - texSRTs[i].scale = pResTexSRTs[i].scale; - } - - TexCoordGen *texCoordGens = GetTexCoordGenAry(); - SetTexCoordGenNum(texCoordGenNum); - for (int i = 0; i < mGXMemNum.texCoordGen; i++) { - texCoordGens[i] = resTexCoordGen[i]; - } - - if (allocChanCtrl) { - const ChanCtrl *pResChanCtrl = detail::ConvertOffsToPtr(pRes, resOffs); - GetChanCtrlAry()[0] = *pResChanCtrl; - resOffs += sizeof(ChanCtrl); - } - - if (allocMatCol) { - const ut::Color *pResMatCol = detail::ConvertOffsToPtr(pRes, resOffs); - GetMatColAry()[0] = *pResMatCol; - resOffs += sizeof(ut::Color); - } - - if (allocTevSwap) { - const TevSwapMode *tevSwaps = detail::ConvertOffsToPtr(pRes, resOffs); - TevSwapMode *pResTevSwap = GetTevSwapAry(); - for (int i = 0; i < 4; i++) { - pResTevSwap[i] = tevSwaps[i]; + TexSRT *texSRTs = GetTexSRTAry(); + for (int i = 0; i < texSRTNum; i++) { + texSRTs[i].translate = pResTexSRTs[i].translate; + texSRTs[i].rotate = pResTexSRTs[i].rotate; + texSRTs[i].scale = pResTexSRTs[i].scale; } - resOffs += 4 * sizeof(TevSwapMode); - } - if (indTexSRTNum != 0) { - TexSRT *indTexSRTs = GetIndTexSRTAry(); - const TexSRT *pResIndMtx = detail::ConvertOffsToPtr(pRes, resOffs); - for (int i = 0; i < indTexSRTNum; i++) { - indTexSRTs[i] = pResIndMtx[i]; + TexCoordGen *texCoordGens = GetTexCoordGenAry(); + SetTexCoordGenNum(texCoordGenNum); + for (int i = 0; i < mGXMemNum.texCoordGen; i++) { + texCoordGens[i] = resTexCoordGen[i]; } - } - resOffs += pRes->resNum.GetIndTexSRTNum() * sizeof(TexSRT); - if (indStageNum != 0) { - SetIndStageNum(indStageNum); - IndirectStage *indirectStages = GetIndirectStageAry(); - const IndirectStage *pResIndStg = detail::ConvertOffsToPtr(pRes, resOffs); - for (int i = 0; i < indStageNum; i++) { - indirectStages[i] = pResIndStg[i]; + if (allocChanCtrl) { + const ChanCtrl *pResChanCtrl = detail::ConvertOffsToPtr(pRes, resOffs); + GetChanCtrlAry()[0] = *pResChanCtrl; + resOffs += sizeof(ChanCtrl); } - } - resOffs += pRes->resNum.GetIndTexStageNum() * sizeof(IndirectStage); - if (tevStageNum != 0) { - SetTevStageNum(tevStageNum); - TevStage *tevStages = GetTevStageAry(); - const TevStage *pResTevStg = detail::ConvertOffsToPtr(pRes, resOffs); - for (int i = 0; i < tevStageNum; i++) { - tevStages[i] = pResTevStg[i]; + if (allocMatCol) { + const ut::Color *pResMatCol = detail::ConvertOffsToPtr(pRes, resOffs); + GetMatColAry()[0] = *pResMatCol; + resOffs += sizeof(ut::Color); } - } - resOffs += pRes->resNum.GetTevStageNum() * sizeof(TevStage); - if (allocAlpComp) { - const AlphaCompare *pResAlphaCompare = detail::ConvertOffsToPtr(pRes, resOffs); - *GetAlphaComparePtr() = *pResAlphaCompare; - resOffs += sizeof(AlphaCompare); - } - if (allocBlendMode) { - const BlendMode *pResBlendMode = detail::ConvertOffsToPtr(pRes, resOffs); - *GetBlendModePtr() = *pResBlendMode; + if (allocTevSwap) { + const TevSwapMode *tevSwaps = detail::ConvertOffsToPtr(pRes, resOffs); + TevSwapMode *pResTevSwap = GetTevSwapAry(); + for (int i = 0; i < 4; i++) { + pResTevSwap[i] = tevSwaps[i]; + } + resOffs += 4 * sizeof(TevSwapMode); + } + + if (indTexSRTNum != 0) { + TexSRT *indTexSRTs = GetIndTexSRTAry(); + const TexSRT *pResIndMtx = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < indTexSRTNum; i++) { + indTexSRTs[i] = pResIndMtx[i]; + } + } + resOffs += pRes->resNum.GetIndTexSRTNum() * sizeof(TexSRT); + + if (indStageNum != 0) { + SetIndStageNum(indStageNum); + IndirectStage *indirectStages = GetIndirectStageAry(); + const IndirectStage *pResIndStg = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < indStageNum; i++) { + indirectStages[i] = pResIndStg[i]; + } + } + resOffs += pRes->resNum.GetIndTexStageNum() * sizeof(IndirectStage); + + if (tevStageNum != 0) { + SetTevStageNum(tevStageNum); + TevStage *tevStages = GetTevStageAry(); + const TevStage *pResTevStg = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < tevStageNum; i++) { + tevStages[i] = pResTevStg[i]; + } + } + resOffs += pRes->resNum.GetTevStageNum() * sizeof(TevStage); + + if (allocAlpComp) { + const AlphaCompare *pResAlphaCompare = detail::ConvertOffsToPtr(pRes, resOffs); + *GetAlphaComparePtr() = *pResAlphaCompare; + resOffs += sizeof(AlphaCompare); + } + if (allocBlendMode) { + const BlendMode *pResBlendMode = detail::ConvertOffsToPtr(pRes, resOffs); + *GetBlendModePtr() = *pResBlendMode; + } } } #pragma dont_inline reset