//
// cocos2d::CCRenderTexture::newCCImage from 0x1006c9080 to 0x1006c92e7 (615 bytes)
//
// 2 xrefs:
// > sub_1006C9030 @ 0x1006c903f
// > sub_1006C9300 @ 0x1006c9315
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:35:35 +0000
//
__int64 __fastcall cocos2d::CCRenderTexture::newCCImage(__int64 a1, char a2)
{
__int64 v3; // rdi
float *ContentSizeInPixels; // rax
GLsizei v5; // r15d
GLsizei v6; // r14d
int v7; // eax
size_t v8; // r12
size_t v9; // rdi
int v10; // r12d
char *pixels; // r13
__int64 v12; // r14
const void *v13; // rsi
int v14; // r13d
__int64 v15; // r15
size_t v16; // rdx
char v17; // al
__int64 v18; // rbx
int v19; // r13d
int v20; // r12d
size_t v21; // r14
__int64 v23; // [rsp+10h] [rbp-70h]
int v24; // [rsp+18h] [rbp-68h]
char v25; // [rsp+20h] [rbp-60h]
size_t __n; // [rsp+28h] [rbp-58h]
int v27; // [rsp+30h] [rbp-50h]
unsigned int v28; // [rsp+34h] [rbp-4Ch]
void *v29; // [rsp+38h] [rbp-48h]
char *v30; // [rsp+40h] [rbp-40h]
int v32; // [rsp+48h] [rbp-38h]
char *__p; // [rsp+50h] [rbp-30h]
v3 = *(_QWORD *)(a1 + 344);
if ( !v3 )
return 0;
ContentSizeInPixels = (float *)cocos2d::CCTexture2D::getContentSizeInPixels(v3);
v5 = (int)*ContentSizeInPixels;
v6 = (int)ContentSizeInPixels[1];
v29 = operator new(0x50u);
cocos2d::CCImage::CCImage((__int64)v29);
v7 = -1;
v28 = 4 * v5 * v6;
if ( v5 * v6 >= 0 )
v7 = 4 * v5 * v6;
v8 = v7;
__p = (char *)operator new[](v7);
v9 = v8;
v10 = v6;
pixels = (char *)operator new[](v9);
cocos2d::CCRenderTexture::begin(a1);
glPixelStorei(0xD05u, 1);
glReadPixels(0, 0, v5, v6, 0x1908u, 0x1401u, pixels);
v12 = cocos2d::CCDirector::sharedDirector();
glBindFramebuffer(0x8D40u, *(_DWORD *)(a1 + 336));
cocos2d::CCDirector::setViewport(v12);
kmGLMatrixMode(5889);
kmGLPopMatrix(5889);
kmGLMatrixMode(5888);
kmGLPopMatrix(5888);
v30 = pixels;
v13 = pixels;
v14 = v5;
v15 = (__int64)v29;
if ( a2 )
{
v13 = __p;
if ( v10 > 0 )
{
v16 = 4 * v14;
v17 = v10;
LODWORD(v18) = 0;
if ( v10 != 1 )
{
v25 = v10;
v23 = v10 & 0x7FFFFFFE;
v27 = 8 * v14;
v24 = v14;
v19 = 4 * v14 * (v10 - 1);
v32 = v10;
v20 = 0;
v18 = 0;
__n = v16;
v21 = v16;
do
{
memcpy(&__p[v20], &v30[v19], v21);
memcpy(&__p[(int)v21 + v20], &v30[(int)(v21 * (v32 + (v18 ^ 0xFFFFFFFE)))], v21);
v18 += 2;
v20 += v27;
v19 -= v27;
}
while ( v23 != v18 );
v15 = (__int64)v29;
v14 = v24;
v10 = v32;
v17 = v25;
v16 = __n;
}
v13 = __p;
if ( (v17 & 1) != 0 )
{
memcpy(&__p[(int)v18 * (int)v16], &v30[(int)v16 * (v10 + ~(_DWORD)v18)], v16);
v13 = __p;
}
}
}
cocos2d::CCImage::initWithImageData(v15, v13, v28, 4, v14, v10, 8);
operator delete[](__p);
operator delete[](v30);
return v15;
}