From d46423af7e1b8c645e1d7021060bf412aeb95506 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Mon, 31 Jul 2023 18:58:47 +0300 Subject: [PATCH] More CGameArea Former-commit-id: 9465f35d9aee6c1feb40375c1a108ee86f15da2d --- asm/MetroidPrime/CGameArea.s | 12 +++--- include/Kyoto/CResLoader.hpp | 1 + src/MetroidPrime/CGameArea.cpp | 67 +++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/asm/MetroidPrime/CGameArea.s b/asm/MetroidPrime/CGameArea.s index 36cea34f..e2daff7d 100644 --- a/asm/MetroidPrime/CGameArea.s +++ b/asm/MetroidPrime/CGameArea.s @@ -29,8 +29,8 @@ lbl_803DA234: .4byte IGetNumAttachedAreas__9CGameAreaCFv .4byte IGetAttachedAreaId__9CGameAreaCFi .4byte IIsActive__9CGameAreaCFv - .4byte IGetAreaAssetID__9CGameAreaCFv - .4byte IGetAreaId__9CGameAreaCFv + .4byte IGetAreaAssetId__9CGameAreaCFv + .4byte IGetAreaSaveId__9CGameAreaCFv .4byte IGetScriptingMemoryAlways__9CGameAreaCFv .global lbl_803DA260 @@ -1237,13 +1237,13 @@ IGetScriptingMemoryAlways__9CGameAreaCFv: /* 8005EB20 0005BA80 38 21 00 10 */ addi r1, r1, 0x10 /* 8005EB24 0005BA84 4E 80 00 20 */ blr -.global IGetAreaId__9CGameAreaCFv -IGetAreaId__9CGameAreaCFv: +.global IGetAreaSaveId__9CGameAreaCFv +IGetAreaSaveId__9CGameAreaCFv: /* 8005EB28 0005BA88 80 63 00 88 */ lwz r3, 0x88(r3) /* 8005EB2C 0005BA8C 4E 80 00 20 */ blr -.global IGetAreaAssetID__9CGameAreaCFv -IGetAreaAssetID__9CGameAreaCFv: +.global IGetAreaAssetId__9CGameAreaCFv +IGetAreaAssetId__9CGameAreaCFv: /* 8005EB30 0005BA90 80 63 00 84 */ lwz r3, 0x84(r3) /* 8005EB34 0005BA94 4E 80 00 20 */ blr diff --git a/include/Kyoto/CResLoader.hpp b/include/Kyoto/CResLoader.hpp index 852d4a97..9b66e015 100644 --- a/include/Kyoto/CResLoader.hpp +++ b/include/Kyoto/CResLoader.hpp @@ -27,6 +27,7 @@ public: void AsyncIdlePakLoading(); bool AreAllPaksLoaded() const; CInputStream* LoadNewResourceSync(const SObjectTag& tag, char* extBuf); + CInputStream* LoadNewResourceSync(const SObjectTag& tag, int, int, char* extBuf); CARAMDvdRequest* LoadResourcePartAsync(const SObjectTag& tag, int, int, char*); FourCC GetResourceTypeById(CAssetId) const; diff --git a/src/MetroidPrime/CGameArea.cpp b/src/MetroidPrime/CGameArea.cpp index 1c1bb605..e9cb5762 100644 --- a/src/MetroidPrime/CGameArea.cpp +++ b/src/MetroidPrime/CGameArea.cpp @@ -1,13 +1,42 @@ #include "MetroidPrime/CGameArea.hpp" -#include "Kyoto/CResFactory.hpp" #include "Kyoto/CDvdRequest.hpp" +#include "Kyoto/CResFactory.hpp" + #define ROUND_UP_32(val) (((val) + 31) & ~31) +rstl::pair< rstl::auto_ptr< uchar >, int > GetScriptingMemoryAlways(const IGameArea& area) { + SObjectTag tag('MREA', area.IGetAreaAssetId()); + + rstl::auto_ptr< char > buf = new char[0x60]; + CInputStream* resource = gpResourceFactory->GetResLoader().LoadNewResourceSync(tag, 0, 0x60, buf.get()); + if (!resource || *(uint*)(buf.get()) != 0xdeadbeef) { + return rstl::pair< rstl::auto_ptr< uchar >, int >(nullptr, 0); + } +} + CGameArea::CPostConstructed::CPostConstructed() {} CGameArea::CPostConstructed::~CPostConstructed() {} +const CTransform4f& CGameArea::IGetTM() const { return xc_transform; } + +CAssetId CGameArea::IGetStringTableAssetId() const { return x8_nameSTRG; } + +uint CGameArea::IGetNumAttachedAreas() const { return x8c_attachedAreaIndices.size(); } + +TAreaId CGameArea::IGetAttachedAreaId(int i) const { return x8c_attachedAreaIndices[i]; } + +bool CGameArea::IIsActive() const { return xf0_25_active; } + +CAssetId CGameArea::IGetAreaAssetId() const { return x84_mrea; } + +int CGameArea::IGetAreaSaveId() const { return x88_areaId; } + +rstl::pair< rstl::auto_ptr< uchar >, int > CGameArea::IGetScriptingMemoryAlways() const { + return GetScriptingMemoryAlways(*this); +} + bool CGameArea::StartStreamingMainArea() { if (xf0_24_postConstructed) return false; @@ -47,21 +76,23 @@ bool CGameArea::StartStreamingMainArea() { int partSizes = GetNumPartSizes(); SObjectTag tag('MREA', x84_mrea); - // for (uint i = 0; i < secCount; ++i) - // totalSz += CBasics::SwapBytes(reinterpret_cast(x110_mreaSecBufs[1].first.get())[i]); + // for (uint i = 0; i < secCount; ++i) + // totalSz += + // CBasics::SwapBytes(reinterpret_cast(x110_mreaSecBufs[1].first.get())[i]); - // AllocNewAreaData(x128_mreaDataOffset, totalSz); + // AllocNewAreaData(x128_mreaDataOffset, totalSz); - // m_resolvedBufs.reserve(secCount); - // m_resolvedBufs.emplace_back(x110_mreaSecBufs[0].first.get(), x110_mreaSecBufs[0].second); - // m_resolvedBufs.emplace_back(x110_mreaSecBufs[1].first.get(), x110_mreaSecBufs[1].second); + // m_resolvedBufs.reserve(secCount); + // m_resolvedBufs.emplace_back(x110_mreaSecBufs[0].first.get(), x110_mreaSecBufs[0].second); + // m_resolvedBufs.emplace_back(x110_mreaSecBufs[1].first.get(), x110_mreaSecBufs[1].second); - // uint curOff = 0; - // for (uint i = 0; i < secCount; ++i) { - // uint size = CBasics::SwapBytes(reinterpret_cast(x110_mreaSecBufs[1].first.get())[i]); - // m_resolvedBufs.emplace_back(x110_mreaSecBufs[2].first.get() + curOff, size); - // curOff += size; - // } + // uint curOff = 0; + // for (uint i = 0; i < secCount; ++i) { + // uint size = + // CBasics::SwapBytes(reinterpret_cast(x110_mreaSecBufs[1].first.get())[i]); + // m_resolvedBufs.emplace_back(x110_mreaSecBufs[2].first.get() + curOff, size); + // curOff += size; + // } int dif = partSizes - secCount; int targetSecCount = secCount; @@ -73,15 +104,15 @@ bool CGameArea::StartStreamingMainArea() { targetSecCount += 1; } - rstl::auto_ptr buf = (char*) CMemory::Alloc(totalSz, IAllocator::kHI_RoundUpLen); + rstl::auto_ptr< char > buf = (char*)CMemory::Alloc(totalSz, IAllocator::kHI_RoundUpLen); xf8_loadTransactions.push_back( - rstl::rc_ptr< CDvdRequest >(gpResourceFactory->GetResLoader().LoadResourcePartAsync(tag, x128_mreaDataOffset, totalSz, buf.get())) - ); + rstl::rc_ptr< CDvdRequest >(gpResourceFactory->GetResLoader().LoadResourcePartAsync( + tag, x128_mreaDataOffset, totalSz, buf.get()))); x128_mreaDataOffset += totalSz; - x110_mreaSecBufs.push_back(rstl::pair< rstl::auto_ptr, int>( buf, 0 )); + x110_mreaSecBufs.push_back(rstl::pair< rstl::auto_ptr< char >, int >(buf, 0)); for (int i = secCount + 1; i < targetSecCount; ++i) { - x110_mreaSecBufs.push_back(rstl::pair< rstl::auto_ptr, int>( nullptr, 0 )); + x110_mreaSecBufs.push_back(rstl::pair< rstl::auto_ptr< char >, int >(nullptr, 0)); } x124_secCount = targetSecCount; if (targetSecCount == partSizes) {