//
// cocos2d::tgaLoad from 0xb21edc to 0xb22148 (620 bytes)
//
// 2 xrefs:
// > cocos2d::CCTileMapAtlas::loadTGAfile @ 0xb3defc
// > ??> @ 0x4f380
//
// 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
//
_QWORD *__fastcall cocos2d::tgaLoad(cocos2d *this, const char *a2)
{
cocos2d::CCFileUtils *v2; // x0
unsigned __int8 *v3; // x20
_QWORD *v4; // x28
int v6; // w21
unsigned int v7; // w23
void *v8; // x0
int v9; // w22
unsigned int v10; // w21
unsigned __int64 v11; // x24
int v12; // w26
int v13; // w0
unsigned __int64 v14; // x1
char v15; // w0
unsigned __int64 v16; // [xsp+68h] [xbp+68h]
int v18; // [xsp+70h] [xbp+70h]
int v19; // [xsp+78h] [xbp+78h]
unsigned __int64 v20; // [xsp+88h] [xbp+88h] BYREF
_BYTE v21[2]; // [xsp+90h] [xbp+90h] BYREF
char v22; // [xsp+92h] [xbp+92h]
v20 = 0;
v2 = cocos2d::CCFileUtils::sharedFileUtils();
v3 = (unsigned __int8 *)((__int64 (__fastcall *)(cocos2d::CCFileUtils *, cocos2d *, char *, unsigned __int64 *))v2->addSearchResolutionsOrder)(
v2,
this,
"rb",
&v20);
if ( !v3 )
return nullptr;
v4 = malloc(0x20u);
if ( (unsigned __int8)cocos2d::tgaLoadHeader((__int64)v3, v20, (__int64)v4) )
{
v6 = *((unsigned __int8 *)v4 + 4);
if ( v6 == 1 )
{
*(_DWORD *)v4 = 3;
goto LABEL_4;
}
if ( (unsigned __int8)(v6 - 2) > 1u && v6 != 10 )
{
*(_DWORD *)v4 = 5;
goto LABEL_4;
}
v7 = *((unsigned __int8 *)v4 + 5) >> 3;
v19 = *((__int16 *)v4 + 4) * *((__int16 *)v4 + 3);
v8 = malloc((int)(v19 * v7));
v4[2] = v8;
if ( v8 )
{
if ( v6 != 10 )
{
if ( !(unsigned __int8)cocos2d::tgaLoadImageData((__int64)v3, v20, (__int64)v4) )
{
*(_DWORD *)v4 = 2;
goto LABEL_4;
}
goto LABEL_20;
}
v16 = v20;
if ( !v19 )
{
LABEL_20:
v13 = *((_DWORD *)v4 + 6);
*(_DWORD *)v4 = 0;
if ( !v13 )
goto LABEL_4;
cocos2d::tgaFlipImage((__int64)v4);
if ( !*((_DWORD *)v4 + 6) )
goto LABEL_4;
goto LABEL_3;
}
v9 = 0;
v10 = 0;
v11 = 18;
v18 = 0;
v12 = 0;
while ( 1 )
{
if ( v12 )
{
v12 = (unsigned __int8)(v12 - 1);
if ( v18 )
goto LABEL_19;
v14 = v11;
}
else
{
v14 = v11 + 1;
if ( v16 < v11 + 1 )
goto LABEL_20;
v12 = v3[v11];
v18 = 0;
if ( (v12 & 0x80) != 0 )
{
v18 = v12 & 0x80;
v12 = (unsigned __int8)(v12 + 0x80);
}
}
v11 = v14 + (unsigned __int8)v7;
if ( v16 < v11 )
goto LABEL_20;
memcpy(v21, &v3[v14], (unsigned __int8)v7);
if ( v7 > 2 )
{
v15 = v21[0];
v21[0] = v22;
v22 = v15;
}
LABEL_19:
memcpy((void *)(v4[2] + v10), v21, (unsigned __int8)v7);
++v9;
v10 += v7;
if ( v19 == v9 )
goto LABEL_20;
}
}
}
LABEL_3:
*(_DWORD *)v4 = 4;
LABEL_4:
operator delete[](v3);
return v4;
}