Fixes to get Metaforce booting again!

This commit is contained in:
Phillip Stephens 2022-02-20 16:03:38 -08:00
parent 8afab43876
commit 1655d229cf
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
5 changed files with 30 additions and 29 deletions

View File

@ -21,16 +21,16 @@ constexpr std::array TypeTable{
CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, metaforce::CInputStream& in, CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, metaforce::CInputStream& in,
const CVParamTransfer& paramXfer, CObjectReference* selfRef) { const CVParamTransfer& paramXfer, CObjectReference* selfRef) {
auto search = m_factories.find(tag.type); auto search = x10_factories.find(tag.type);
if (search == m_factories.end()) if (search == x10_factories.end())
return {}; return {};
return search->second(tag, in, paramXfer, selfRef); return search->second(tag, in, paramXfer, selfRef);
} }
bool CFactoryMgr::CanMakeMemory(const metaforce::SObjectTag& tag) const { bool CFactoryMgr::CanMakeMemory(const metaforce::SObjectTag& tag) const {
auto search = m_memFactories.find(tag.type); auto search = x24_memFactories.find(tag.type);
return search != m_memFactories.cend(); return search != x24_memFactories.cend();
} }
CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr<u8[]>&& buf, int size, CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr<u8[]>&& buf, int size,
@ -39,8 +39,8 @@ CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::u
OPTICK_EVENT(); OPTICK_EVENT();
std::unique_ptr<u8[]> localBuf = std::move(buf); std::unique_ptr<u8[]> localBuf = std::move(buf);
const auto memFactoryIter = m_memFactories.find(tag.type); const auto memFactoryIter = x24_memFactories.find(tag.type);
if (memFactoryIter != m_memFactories.cend()) { if (memFactoryIter != x24_memFactories.cend()) {
if (compressed) { if (compressed) {
std::unique_ptr<CInputStream> compRead = std::unique_ptr<CInputStream> compRead =
std::make_unique<CMemoryInStream>(localBuf.get(), size, CMemoryInStream::EOwnerShip::NotOwned); std::make_unique<CMemoryInStream>(localBuf.get(), size, CMemoryInStream::EOwnerShip::NotOwned);
@ -53,8 +53,8 @@ CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::u
return memFactoryIter->second(tag, std::move(localBuf), size, paramXfer, selfRef); return memFactoryIter->second(tag, std::move(localBuf), size, paramXfer, selfRef);
} }
} else { } else {
const auto factoryIter = m_factories.find(tag.type); const auto factoryIter = x10_factories.find(tag.type);
if (factoryIter == m_factories.end()) { if (factoryIter == x10_factories.end()) {
return {}; return {};
} }

View File

@ -12,8 +12,8 @@ class CVParamTransfer;
class IObj; class IObj;
class CFactoryMgr { class CFactoryMgr {
std::unordered_map<FourCC, FFactoryFunc> m_factories; std::unordered_map<FourCC, FFactoryFunc> x10_factories;
std::unordered_map<FourCC, FMemFactoryFunc> m_memFactories; std::unordered_map<FourCC, FMemFactoryFunc> x24_memFactories;
public: public:
CFactoryFnReturn MakeObject(const SObjectTag& tag, metaforce::CInputStream& in, const CVParamTransfer& paramXfer, CFactoryFnReturn MakeObject(const SObjectTag& tag, metaforce::CInputStream& in, const CVParamTransfer& paramXfer,
@ -21,8 +21,8 @@ public:
bool CanMakeMemory(const metaforce::SObjectTag& tag) const; bool CanMakeMemory(const metaforce::SObjectTag& tag) const;
CFactoryFnReturn MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr<u8[]>&& buf, int size, bool compressed, CFactoryFnReturn MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr<u8[]>&& buf, int size, bool compressed,
const CVParamTransfer& paramXfer, CObjectReference* selfRef); const CVParamTransfer& paramXfer, CObjectReference* selfRef);
void AddFactory(FourCC key, FFactoryFunc func) { m_factories.insert_or_assign(key, std::move(func)); } void AddFactory(FourCC key, FFactoryFunc func) { x10_factories.insert_or_assign(key, std::move(func)); }
void AddFactory(FourCC key, FMemFactoryFunc func) { m_memFactories.insert_or_assign(key, std::move(func)); } void AddFactory(FourCC key, FMemFactoryFunc func) { x24_memFactories.insert_or_assign(key, std::move(func)); }
enum class ETypeTable : u8 { enum class ETypeTable : u8 {
CLSN, CLSN,

View File

@ -7,8 +7,8 @@
namespace metaforce { namespace metaforce {
static u32 ReadCount(CInputStream& in) { static u32 ReadCount(CInputStream& in) {
u32 result = in.ReadLong(); s32 result = in.ReadLong();
if (result == UINT32_MAX) { if (result == -1) {
return in.ReadLong(); return in.ReadLong();
} }
u8 junk[784]; u8 junk[784];

View File

@ -32,8 +32,8 @@ public:
class CSkinRules { class CSkinRules {
std::vector<CVirtualBone> x0_bones; std::vector<CVirtualBone> x0_bones;
u32 x10_vertexCount; u32 x10_vertexCount = 0;
u32 x14_normalCount; u32 x14_normalCount = 0;
public: public:
explicit CSkinRules(CInputStream& in); explicit CSkinRules(CInputStream& in);

View File

@ -31,29 +31,30 @@ bool CInputStream::InternalReadNext() {
bool CInputStream::GrabAnotherBlock() { return InternalReadNext(); } bool CInputStream::GrabAnotherBlock() { return InternalReadNext(); }
void CInputStream::Get(u8* dest, u32 len) { void CInputStream::Get(u8* dest, u32 len) {
u32 readLen = 0;
x20_bitOffset = 0; x20_bitOffset = 0;
u32 readCount = 0;
while (len != 0) { while (len != 0) {
u32 blockLen = x8_blockLen - x4_blockOffset; u32 blockLen = x8_blockLen - x4_blockOffset;
if (len < blockLen) { if (len < blockLen) {
blockLen = len; blockLen = len;
} }
if (blockLen == 0) {
if (blockLen != 0) { if (len <= 256) {
memcpy(dest + readLen, x10_ptr + x4_blockOffset, blockLen); GrabAnotherBlock();
len -= blockLen; } else {
readLen += blockLen; u32 readLen = Read(dest + readCount, len);
x4_blockOffset += blockLen; len -= readLen;
} else if (len > 256) { readCount += readLen;
u32 tmp = Read(dest + readLen, len); }
len -= tmp;
readLen += tmp;
} else { } else {
GrabAnotherBlock(); memcpy(dest + readCount, x10_ptr + x4_blockOffset, blockLen);
len -= blockLen;
readCount += blockLen;
x4_blockOffset += blockLen;
} }
} }
x18_readPosition += readLen; x18_readPosition += readCount;
} }
u32 CInputStream::ReadBytes(void* dest, u32 len) { u32 CInputStream::ReadBytes(void* dest, u32 len) {