//
// cocos2d::CCImage::saveToFile from 0xd7e244 to 0xd7e4ec (680 bytes)
//
// 3 xrefs:
// > cocos2d::CCRenderTexture::saveToFile @ 0xd6b4f4
// > cocos2d::CCRenderTexture::saveToFile @ 0xd6b614
// > ??> @ 0x7fcc0
//
// This function is hookable on this platform (idp: arm, 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 13:08:08 +0000
//
__int64 __fastcall cocos2d::CCImage::saveToFile(cocos2d::CCImage *this, char *a2, unsigned __int8 a3)
{
size_t v6; // x0
unsigned int i; // w25
unsigned __int64 v9; // x2
char *v10; // x19
char *v11; // x19
char *v12; // x0
int v13; // w0
unsigned __int8 v14; // w0
int v15; // w3
char *v16; // x23
char *v17; // x19
__int64 v18; // x0
char *v19; // x26
unsigned __int64 v20; // x0
char *v21; // x19
__int64 v22; // x0
__int64 v23; // [xsp+58h] [xbp+58h] BYREF
size_t v24; // [xsp+60h] [xbp+60h]
void *v25; // [xsp+68h] [xbp+68h]
__int64 v26; // [xsp+70h] [xbp+70h] BYREF
unsigned __int64 v27; // [xsp+78h] [xbp+78h]
void *v28; // [xsp+80h] [xbp+80h]
if ( !a2 )
return 0;
v23 = 0;
v24 = 0;
v25 = nullptr;
v6 = strlen(a2);
std::string::__init(&v23, a2, v6);
if ( (v23 & 1) != 0 )
{
if ( v24 <= 4 )
goto LABEL_4;
v26 = 0;
v27 = 0;
v28 = nullptr;
std::string::__init(&v26, v25, v24);
}
else
{
if ( (unsigned __int8)v23 <= 9u )
return 0;
v28 = v25;
v26 = v23;
v27 = v24;
}
for ( i = 0; ; ++i )
{
v14 = v26;
v15 = v26 & 1;
if ( (v26 & 1) == 0 )
break;
v9 = v27;
if ( i >= v27 )
{
v16 = (char *)v28;
v15 = 1;
if ( v27 > 3 )
goto LABEL_19;
goto LABEL_28;
}
v10 = (char *)v28;
LABEL_11:
v11 = &v10[i];
v12 = (char *)&v23 + 1;
if ( (v23 & 1) != 0 )
v12 = (char *)v25;
v13 = (unsigned __int8)v12[i];
*v11 = tolower(v13);
}
v9 = (unsigned __int8)v26 >> 1;
if ( i < v9 )
{
v10 = (char *)&v26 + 1;
goto LABEL_11;
}
v16 = (char *)&v26 + 1;
if ( v9 > 3 )
{
LABEL_19:
v17 = &v16[v9];
v18 = std::__search(
(__int64)v16,
(__int64)&v16[v9],
(unsigned __int8 *)".png",
(unsigned __int8 *)"",
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v17 != (char *)v18 && v18 - (_QWORD)v16 != -1 )
{
if ( (unsigned __int8)cocos2d::CCImage::_saveImageToPNG(this, a2, a3) )
{
LABEL_22:
if ( (v26 & 1) != 0 )
operator delete(v28);
if ( (v23 & 1) != 0 )
operator delete(v25);
return 1;
}
goto LABEL_34;
}
v14 = v26;
v15 = v26 & 1;
}
LABEL_28:
if ( v15 )
{
v19 = (char *)v28;
v20 = v27;
}
else
{
v20 = v14 >> 1;
v19 = (char *)&v26 + 1;
}
if ( v20 > 3 )
{
v21 = &v19[v20];
v22 = std::__search(
(__int64)v19,
(__int64)&v19[v20],
".jpg",
(unsigned __int8 *)"",
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v21 != (char *)v22 && v22 - (_QWORD)v19 != -1 && (unsigned __int8)cocos2d::CCImage::_saveImageToJPG(this, a2) )
goto LABEL_22;
LABEL_34:
v15 = v26 & 1;
}
if ( v15 )
operator delete(v28);
if ( (v23 & 1) != 0 )
LABEL_4:
operator delete(v25);
return 0;
}