//
// cocos2d::tgaLoad from 0x5ecc88 to 0x5ecdd2 (330 bytes)
//
// 1 xrefs:
// > cocos2d::CCTileMapAtlas::loadTGAfile @ 0x5fa032
//
// 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
//
_DWORD *__fastcall cocos2d::tgaLoad(cocos2d *this, const char *a2)
{
cocos2d::CCFileUtils *v3; // r0
unsigned __int8 *v4; // r7
_DWORD *v5; // r4
int v6; // r5
int v7; // r3
size_t v8; // r6
void *v9; // r0
int v10; // r5
int v11; // r1
int v12; // r8
int v13; // r9
int v14; // r10
size_t v15; // r11
char v16; // r1
void *v17; // r0
int v19; // [sp+0h] [bp-24h]
unsigned int v20; // [sp+4h] [bp-20h]
unsigned int v21; // [sp+14h] [bp-10h] BYREF
_BYTE v22[2]; // [sp+18h] [bp-Ch] BYREF
char v23; // [sp+1Ah] [bp-Ah]
v21 = 0;
v3 = cocos2d::CCFileUtils::sharedFileUtils();
v4 = (unsigned __int8 *)((int (__fastcall *)(cocos2d::CCFileUtils *, cocos2d *, const char *, unsigned int *))v3->addSearchResolutionsOrder)(
v3,
this,
"rb",
&v21);
if ( v4 )
{
v5 = malloc(0x14u);
if ( cocos2d::tgaLoadHeader((int)v4, v21, (int)v5) )
{
v6 = *((unsigned __int8 *)v5 + 4);
if ( v6 == 1 )
{
v7 = 3;
LABEL_28:
*v5 = v7;
LABEL_31:
operator delete[](v4);
return v5;
}
if ( (unsigned int)(v6 - 2) > 1 && v6 != 10 )
{
v7 = 5;
goto LABEL_28;
}
v8 = *((unsigned __int8 *)v5 + 5) >> 3;
v19 = *((__int16 *)v5 + 4) * *((__int16 *)v5 + 3);
v9 = malloc(v8 * v19);
v5[3] = v9;
if ( v9 )
{
if ( v6 == 10 )
{
v10 = 0;
v11 = 18;
v12 = 0;
v13 = 0;
v14 = 0;
v20 = v21;
while ( 1 )
{
if ( v14 == v19 )
goto LABEL_25;
if ( v10 )
{
v10 = (unsigned __int8)(v10 - 1);
if ( v12 )
{
v15 = v11;
goto LABEL_22;
}
}
else
{
if ( v11 + 1 > v20 )
goto LABEL_25;
v10 = v4[v11];
v12 = v10 & 0x80;
if ( (v10 & 0xFFFFFF80) != 0 )
v10 ^= 0x80u;
++v11;
}
v15 = v11 + v8;
if ( v11 + v8 > v20 )
goto LABEL_25;
memcpy(v22, &v4[v11], v8);
if ( v8 > 2 )
{
v16 = v23;
v23 = v22[0];
v22[0] = v16;
}
LABEL_22:
++v14;
v17 = (void *)(v5[3] + v13);
v13 += v8;
memcpy(v17, v22, v8);
v11 = v15;
}
}
if ( !cocos2d::tgaLoadImageData((int)v4, v21, (int)v5) )
{
v7 = 2;
goto LABEL_28;
}
LABEL_25:
*v5 = 0;
if ( !v5[4] )
goto LABEL_31;
cocos2d::tgaFlipImage((int)v5);
if ( !v5[4] )
goto LABEL_31;
}
}
v7 = 4;
goto LABEL_28;
}
return nullptr;
}