mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-11-22 21:42:28 +01:00
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#include "StdAfxSA.h"
|
|
#include "PNGFile.h"
|
|
|
|
RwTexture* CPNGFile::ReadFromFile(const char* pFileName)
|
|
{
|
|
RwTexture* pTexture = nullptr;
|
|
|
|
if ( RwImage* pImage = RtPNGImageRead(pFileName) )
|
|
{
|
|
RwInt32 dwWidth, dwHeight, dwDepth, dwFlags;
|
|
RwImageFindRasterFormat(pImage, rwRASTERTYPETEXTURE, &dwWidth, &dwHeight, &dwDepth, &dwFlags);
|
|
if ( RwRaster* pRaster = RwRasterCreate(dwWidth, dwHeight, dwDepth, dwFlags) )
|
|
{
|
|
RwRasterSetFromImage(pRaster, pImage);
|
|
|
|
pTexture = RwTextureCreate(pRaster);
|
|
//if ( pTexture )
|
|
// RwTextureSetName(pTexture, pFileName);
|
|
}
|
|
RwImageDestroy(pImage);
|
|
}
|
|
return pTexture;
|
|
}
|
|
|
|
RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen)
|
|
{
|
|
static BYTE* pMem = AddressByVersion<BYTE*>(0x7CF9CA, 0x7D02CA, 0x80998A);
|
|
RwTexture* pTexture = nullptr;
|
|
|
|
MemoryVP::Patch<BYTE>(pMem, rwSTREAMMEMORY);
|
|
|
|
RwMemory PNGMemory;
|
|
PNGMemory.start = const_cast<RwUInt8*>(static_cast<const RwUInt8*>(pMemory));
|
|
PNGMemory.length = nLen;
|
|
|
|
if ( RwImage* pImage = RtPNGImageRead(reinterpret_cast<RwChar*>(&PNGMemory)) )
|
|
{
|
|
RwInt32 dwWidth, dwHeight, dwDepth, dwFlags;
|
|
RwImageFindRasterFormat(pImage, rwRASTERTYPETEXTURE, &dwWidth, &dwHeight, &dwDepth, &dwFlags);
|
|
if ( RwRaster* pRaster = RwRasterCreate(dwWidth, dwHeight, dwDepth, dwFlags) )
|
|
{
|
|
RwRasterSetFromImage(pRaster, pImage);
|
|
|
|
pTexture = RwTextureCreate(pRaster);
|
|
//if ( pTexture )
|
|
// RwTextureSetName(pTexture, pFileName);
|
|
}
|
|
RwImageDestroy(pImage);
|
|
}
|
|
|
|
MemoryVP::Patch<BYTE>(pMem, rwSTREAMFILENAME);
|
|
|
|
return pTexture;
|
|
} |