//
// cocos2d::CCRenderTexture::newCCImage from 0x1800602c0 to 0x1800604c7 (519 bytes)
//
// 4 xrefs:
// > cocos2d::CCRenderTexture::saveToFile @ 0x1800604df
// > cocos2d::CCRenderTexture::saveToFile @ 0x18006055b
// > ??> @ 0x1801438a8
// > ??> @ 0x1801b3468
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
// Hidden C++ exception states: #wind=1
struct cocos2d::CCImage *__fastcall cocos2d::CCRenderTexture::newCCImage(cocos2d::CCRenderTexture *this, char a2)
{
cocos2d::CCTexture2D *m_pTexture; // rcx
const struct cocos2d::CCSize *ContentSizeInPixels; // rax
GLsizei width; // ebp
GLsizei height; // r12d
cocos2d::CCImage *v8; // rax
__int64 v9; // rbx
int v10; // r15d
char *v11; // r14
char *pixels; // r13
char *v13; // rcx
cocos2d::CCDirector *v14; // rbx
size_t v15; // rsi
char *v16; // rdi
char *v17; // rbx
__int64 v18; // rbp
char *v19; // rdx
__int64 v20; // [rsp+40h] [rbp-58h]
GLsizei v22; // [rsp+B0h] [rbp+18h]
cocos2d::CCImage *v23; // [rsp+B8h] [rbp+20h]
m_pTexture = this->m_pTexture;
if ( !m_pTexture )
return nullptr;
ContentSizeInPixels = cocos2d::CCTexture2D::getContentSizeInPixels(m_pTexture);
width = (int)ContentSizeInPixels->width;
v22 = width;
height = (int)ContentSizeInPixels->height;
v8 = (cocos2d::CCImage *)operator new(0x50u);
if ( v8 )
v9 = cocos2d::CCImage::CCImage(v8);
else
v9 = 0;
v23 = (cocos2d::CCImage *)v9;
v10 = 4 * width * height;
v11 = (char *)operator new(v10);
if ( v11 )
{
pixels = (char *)operator new(v10);
if ( pixels )
{
cocos2d::CCRenderTexture::begin(this);
glPixelStorei(0xD05u, 1);
glReadPixels(0, 0, width, height, 0x1908u, 0x1401u, pixels);
v14 = cocos2d::CCDirector::sharedDirector();
_glewBindFramebuffer(36160, (unsigned int)this->m_nOldFBO);
cocos2d::CCDirector::setViewport(v14);
kmGLMatrixMode(5889);
kmGLPopMatrix();
kmGLMatrixMode(5888);
kmGLPopMatrix();
if ( a2 )
{
if ( height > 0 )
{
v15 = 4 * width;
v16 = v11;
v20 = -4 * width;
v17 = &pixels[width * (4 * height - 4)];
v18 = (unsigned int)height;
do
{
memcpy(v16, v17, v15);
v17 += v20;
v16 += v15;
--v18;
}
while ( v18 );
width = v22;
}
v19 = v11;
}
else
{
v19 = pixels;
}
v9 = (__int64)v23;
cocos2d::CCImage::initWithImageData(v23, v19, v10, kFmtRawData, width, height, 8, 0);
j_j_free_0(v11);
v13 = pixels;
}
else
{
v13 = v11;
}
j_j_free_0(v13);
}
return (struct cocos2d::CCImage *)v9;
}