From 487dcc4bde45a06a2a5132a52c6d175794f9e8da Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 3 Mar 2022 00:24:46 -0800 Subject: [PATCH] CSkinRules: Fix ReadCount not incrementing offset properly --- Runtime/Character/CSkinRules.cpp | 5 +++-- Runtime/Graphics/DolphinCTexture.cpp | 4 ++++ Runtime/Graphics/DolphinCTexture.hpp | 1 + Runtime/Streams/CInputStream.cpp | 9 +++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Runtime/Character/CSkinRules.cpp b/Runtime/Character/CSkinRules.cpp index c2ae2c722..4009a6494 100644 --- a/Runtime/Character/CSkinRules.cpp +++ b/Runtime/Character/CSkinRules.cpp @@ -12,8 +12,9 @@ static u32 ReadCount(CInputStream& in) { return in.ReadLong(); } u8 junk[784]; - for (u32 i = 0; i < (result * 3); ++i) { - u32 iVar2 = ((result * 3) - i); + u32 iVar2 = 0; + for (u32 i = 0; i < (result * 3); i += iVar2) { + iVar2 = ((result * 3) - i); iVar2 = 192 < iVar2 ? 192 : iVar2; in.Get(junk, iVar2 * 4); } diff --git a/Runtime/Graphics/DolphinCTexture.cpp b/Runtime/Graphics/DolphinCTexture.cpp index 57bb789a2..9a487254c 100644 --- a/Runtime/Graphics/DolphinCTexture.cpp +++ b/Runtime/Graphics/DolphinCTexture.cpp @@ -325,6 +325,10 @@ bool CTexture::sMangleMips = false; u32 CTexture::sCurrentFrameCount = 0; u32 CTexture::sTotalAllocatedMemory = 0; +void CTexture::InvalidateTexMap(GX::TexMapID id) { + sLoadedTextures[id] = nullptr; +} + CFactoryFnReturn FTextureFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef) { return TToken::GetIObjObjectFor(std::make_unique(in)); diff --git a/Runtime/Graphics/DolphinCTexture.hpp b/Runtime/Graphics/DolphinCTexture.hpp index 4a89df29f..155e813fa 100644 --- a/Runtime/Graphics/DolphinCTexture.hpp +++ b/Runtime/Graphics/DolphinCTexture.hpp @@ -95,6 +95,7 @@ public: return x0_fmt == ETexelFormat::C4 || x0_fmt == ETexelFormat::C8 || x0_fmt == ETexelFormat::C14X2; } + static void InvalidateTexMap(GX::TexMapID id); static void SetMangleMips(bool b) { sMangleMips = b; } static void SetCurrentFrameCount(u32 frameCount) { sCurrentFrameCount = frameCount; } }; diff --git a/Runtime/Streams/CInputStream.cpp b/Runtime/Streams/CInputStream.cpp index 01ddc3e62..2703c9ac4 100644 --- a/Runtime/Streams/CInputStream.cpp +++ b/Runtime/Streams/CInputStream.cpp @@ -4,8 +4,11 @@ #endif #include +#include namespace metaforce { +static logvisor::Module Log("metaforce::CInputStream"); + static u32 min_containing_bytes(u32 v) { v = 32 - v; v = (v >> 3) - (static_cast(-(v & 7)) >> 31); @@ -46,6 +49,12 @@ void CInputStream::Get(u8* dest, u32 len) { x4_blockOffset += blockLen; } else if (len > 256) { u32 readLen = Read(dest + readCount, len); +#ifndef NDEBUG + if (readLen == 0) { + Log.report(logvisor::Fatal, FMT_STRING("Invalid read size!")); + break; + } +#endif len -= readLen; readCount += readLen; } else {