From fe46468e7c11b2c5e01ab88fc12412a509306c11 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 9 Apr 2017 23:17:49 +0200 Subject: [PATCH] Safer CPNGFile::ReadFromMemory --- SilentPatchSA/PNGFile.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SilentPatchSA/PNGFile.cpp b/SilentPatchSA/PNGFile.cpp index 1995e71..c37de55 100644 --- a/SilentPatchSA/PNGFile.cpp +++ b/SilentPatchSA/PNGFile.cpp @@ -24,10 +24,11 @@ RwTexture* CPNGFile::ReadFromFile(const char* pFileName) RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen) { - static BYTE* pMem = AddressByVersion(0x7CF9CA, 0x7D02CA, 0x80998A); - RwTexture* pTexture = nullptr; + static uint8_t* const pMem = AddressByVersion(0x7CF9CA, 0x7D02CA, 0x80998A); + RwTexture* pTexture = nullptr; - Memory::VP::Patch(pMem, rwSTREAMMEMORY); + uint8_t oldMemory = *pMem; + Memory::VP::Patch(pMem, rwSTREAMMEMORY); RwMemory PNGMemory; PNGMemory.start = const_cast(static_cast(pMemory)); @@ -48,7 +49,7 @@ RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen) RwImageDestroy(pImage); } - Memory::VP::Patch(pMem, rwSTREAMFILENAME); + Memory::VP::Patch(pMem, oldMemory); return pTexture; } \ No newline at end of file