mirror of https://github.com/AxioDL/metaforce.git
Fix CInputStream::Get/ReadBytes not properly updating position
This commit is contained in:
parent
dad7249927
commit
ce23544a15
|
@ -31,30 +31,29 @@ 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 offset = 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();
|
|
||||||
} else {
|
|
||||||
u32 readLen = Read(dest + offset, len);
|
|
||||||
len -= readLen;
|
|
||||||
offset += readLen;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
memcpy(dest + offset, x10_ptr + x4_blockOffset, blockLen);
|
|
||||||
len -= blockLen;
|
len -= blockLen;
|
||||||
|
readLen += blockLen;
|
||||||
x4_blockOffset += blockLen;
|
x4_blockOffset += blockLen;
|
||||||
|
} else if (len > 256) {
|
||||||
|
u32 tmp = Read(dest + readLen, len);
|
||||||
|
len -= tmp;
|
||||||
|
readLen += tmp;
|
||||||
|
} else {
|
||||||
|
GrabAnotherBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x18_readPosition += offset;
|
x18_readPosition += readLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 CInputStream::ReadBytes(void* dest, u32 len) {
|
u32 CInputStream::ReadBytes(void* dest, u32 len) {
|
||||||
|
@ -66,31 +65,26 @@ u32 CInputStream::ReadBytes(void* dest, u32 len) {
|
||||||
GrabAnotherBlock();
|
GrabAnotherBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 curReadLen = 0;
|
|
||||||
u32 curLen = len;
|
u32 curLen = len;
|
||||||
|
u32 curReadLen = 0;
|
||||||
|
|
||||||
do {
|
while (curReadLen < len) {
|
||||||
while (true) {
|
if ((x8_blockLen - x4_blockOffset) == 0 && !InternalReadNext()) {
|
||||||
if (len <= curReadLen) {
|
|
||||||
x18_readPosition += curReadLen;
|
|
||||||
return curReadLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 readCount = x8_blockLen - x4_blockOffset;
|
|
||||||
if (readCount == 0) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curLen < readCount) {
|
u32 readCount = x8_blockLen - x4_blockOffset;
|
||||||
|
if (curLen < (x8_blockLen - x4_blockOffset)) {
|
||||||
readCount = curLen;
|
readCount = curLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(reinterpret_cast<u8*>(dest) + curReadLen, x10_ptr + x4_blockOffset, readCount);
|
memcpy(reinterpret_cast<u8*>(dest) + curReadLen, x10_ptr + x4_blockOffset, readCount);
|
||||||
curReadLen += readCount;
|
curReadLen += readCount;
|
||||||
curLen -= readCount;
|
curLen -= readCount;
|
||||||
|
x4_blockOffset += readCount;
|
||||||
}
|
}
|
||||||
} while (InternalReadNext());
|
|
||||||
|
|
||||||
|
x18_readPosition += curReadLen;
|
||||||
return curReadLen;
|
return curReadLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,13 @@ namespace metaforce {
|
||||||
logvisor::Module Log("metaforce::RetroTypes::CAssetId");
|
logvisor::Module Log("metaforce::RetroTypes::CAssetId");
|
||||||
|
|
||||||
SObjectTag::SObjectTag(CInputStream& in) {
|
SObjectTag::SObjectTag(CInputStream& in) {
|
||||||
in.ReadBytes(reinterpret_cast<char*>(&type), 4);
|
in.Get(reinterpret_cast<u8*>(&type), 4);
|
||||||
id = in.Get<CAssetId>();
|
id = in.Get<CAssetId>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SObjectTag::ReadMLVL(CInputStream& in) {
|
void SObjectTag::ReadMLVL(CInputStream& in) {
|
||||||
id = in.Get<CAssetId>();
|
id = in.Get<CAssetId>();
|
||||||
in.ReadBytes(reinterpret_cast<char*>(&type), 4);
|
in.Get(reinterpret_cast<u8*>(&type), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAssetId::CAssetId(CInputStream& in) {
|
CAssetId::CAssetId(CInputStream& in) {
|
||||||
|
|
|
@ -599,9 +599,9 @@ void CEnvFxManager::Cleanup() {
|
||||||
void CEnvFxManager::Initialize() {
|
void CEnvFxManager::Initialize() {
|
||||||
const SObjectTag* tag = g_ResFactory->GetResourceIdByName("DUMB_SnowForces");
|
const SObjectTag* tag = g_ResFactory->GetResourceIdByName("DUMB_SnowForces");
|
||||||
std::unique_ptr<u8[]> data = g_ResFactory->LoadResourceSync(*tag);
|
std::unique_ptr<u8[]> data = g_ResFactory->LoadResourceSync(*tag);
|
||||||
athena::io::MemoryReader r(data.get(), 2048);
|
CMemoryInStream r(data.get(), 2048, CMemoryInStream::EOwnerShip::NotOwned);
|
||||||
for (int i = 0; i < 256; ++i)
|
for (int i = 0; i < 256; ++i)
|
||||||
g_SnowForces.push_back(r.readVec2fBig());
|
g_SnowForces.push_back(r.Get<zeus::CVector2f>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace metaforce
|
} // namespace metaforce
|
||||||
|
|
Loading…
Reference in New Issue