//
// cocos2d::CCTexturePVR::initWithContentsOfFile from 0xb37ba4 to 0xb37e2c (648 bytes)
//
// 3 xrefs:
// > cocos2d::CCTexture2D::initWithPVRFile @ 0xb31408
// > cocos2d::CCTexturePVR::create @ 0xb37e54
// > ??> @ 0x66b28
//
// 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
//
bool cocos2d::CCTexturePVR::initWithContentsOfFile(cocos2d::CCTexturePVR *a1, const char *a2)
{
__int64 v2; // x20
unsigned int v4; // w21
__int64 v6; // x0
_BYTE *v7; // x26
unsigned __int8 *v8; // x0
unsigned __int8 **v9; // x2
unsigned int v10; // w2
unsigned __int8 *v11; // x1
bool GLTexture; // w19
__int64 v13; // x2
void *v14; // x0
unsigned int *v16; // x2
int v17; // w1
unsigned __int8 **v18; // x2
cocos2d::CCFileUtils *v19; // x0
unsigned int v20; // [xsp+54h] [xbp+54h] BYREF
void *p; // [xsp+58h] [xbp+58h] BYREF
__int64 v22; // [xsp+60h] [xbp+60h] BYREF
v2 = 0;
v4 = 0;
p = nullptr;
v20 = 0;
sub_D153B8((int)&v22, (char *)a2);
v6 = v22;
if ( *(_QWORD *)(v22 - 24) )
{
do
{
if ( (*(_DWORD *)(v6 - 8) & 0x80000000) == 0 )
sub_D176A8(&v22);
v7 = (_BYTE *)(v22 + v2);
v8 = (unsigned __int8 *)(v22 + v2);
if ( (*(_DWORD *)(v22 - 8) & 0x80000000) == 0 )
{
sub_D176A8(&v22);
v8 = (unsigned __int8 *)(v22 + v2);
}
v2 = ++v4;
*v7 = tolower(*v8);
v6 = v22;
}
while ( (unsigned __int64)v4 < *(_QWORD *)(v22 - 24) );
}
if ( sub_D1641C((int)&v22, ".ccz") == -1 )
{
if ( sub_D1641C((int)&v22, ".gz") == -1 )
{
v19 = cocos2d::CCFileUtils::sharedFileUtils();
p = (void *)((__int64 (__fastcall *)(cocos2d::CCFileUtils *, const char *, char *, unsigned int *))v19->addSearchResolutionsOrder)(
v19,
a2,
"rb",
&v20);
v10 = v20;
}
else
{
v10 = cocos2d::ZipUtils::ccInflateGZipFile((cocos2d::ZipUtils *)a2, (char *)&p, v18);
v20 = v10;
}
}
else
{
v10 = cocos2d::ZipUtils::ccInflateCCZFile((cocos2d::ZipUtils *)a2, (char *)&p, v9);
v20 = v10;
}
if ( (v10 & 0x80000000) != 0 )
goto LABEL_14;
v11 = (unsigned __int8 *)p;
a1[5].m_uIndexInArray = 0;
a1[5].m_nZOrder = 0;
a1[5].m_unknown2 = 0;
a1[5].m_uUnknown = 0;
a1[6].__vftable = nullptr;
LOBYTE(a1[5].m_uOrderOfArrival) = 0;
BYTE2(a1[5].m_uOrderOfArrival) = 0;
BYTE1(a1[5].m_uOrderOfArrival) = 0;
HIBYTE(a1[5].m_uOrderOfArrival) = 0;
if ( !cocos2d::CCTexturePVR::unpackPVRv2Data(a1, v11, v10)
&& !cocos2d::CCTexturePVR::unpackPVRv3Data(a1, (unsigned __int8 *)p, v20)
|| !(GLTexture = cocos2d::CCTexturePVR::createGLTexture(a1)) )
{
if ( p )
{
operator delete[](p);
p = nullptr;
}
LABEL_14:
GLTexture = 0;
cocos2d::CCObject::release(a1);
goto LABEL_15;
}
if ( !p )
{
LABEL_15:
v13 = v22;
v14 = (void *)(v22 - 24);
if ( (__int64 *)(v22 - 24) == &qword_124B6B0 )
return GLTexture;
goto LABEL_20;
}
operator delete[](p);
p = nullptr;
v13 = v22;
v14 = (void *)(v22 - 24);
if ( (__int64 *)(v22 - 24) == &qword_124B6B0 )
return GLTexture;
LABEL_20:
if ( &pthread_create )
{
v16 = (unsigned int *)(v13 - 8);
do
v17 = __ldaxr(v16);
while ( __stlxr(v17 - 1, v16) );
}
else
{
v17 = *(_DWORD *)(v13 - 8);
*(_DWORD *)(v13 - 8) = v17 - 1;
}
if ( v17 <= 0 )
operator delete(v14);
return GLTexture;
}