//
// sub_18009E3D0 from 0x18009e3d0 to 0x18009e77f (943 bytes)
//
// 4 xrefs:
// > cocos2d::CCTileMapAtlas::loadTGAfile @ 0x1800ab38b
// > ??> @ 0x18013f030
// > ??> @ 0x18013f040
// > ??> @ 0x1801b759c
//
// 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
//
__int64 __fastcall sub_18009E3D0(__int64 a1)
{
struct cocos2d::CCFileUtils *v2; // rax
__int64 result; // rax
__int64 v4; // r15
_BYTE *v5; // rsi
unsigned int v6; // eax
char v7; // bl
int v8; // ecx
int v9; // edx
unsigned int v10; // r8d
bool v11; // zf
int v12; // r12d
unsigned int v13; // r14d
int v14; // ebp
char *v15; // rdi
int v16; // eax
unsigned int v17; // ecx
int v18; // ebp
int v19; // r12d
char v20; // di
__int64 v21; // rbx
size_t v22; // r8
unsigned __int64 v23; // rdx
size_t v24; // r13
char v25; // cl
__int64 v26; // r12
char v27; // cl
bool v28; // cf
int v29; // r14d
void *v30; // r13
int v31; // ebx
int v32; // r12d
__int64 v33; // r15
char *v34; // rdi
char *v35; // rbx
signed __int64 v36; // rbx
signed __int64 i; // rdx
char v38; // cl
int v39; // [rsp+20h] [rbp-68h]
int v40; // [rsp+24h] [rbp-64h]
char *v41; // [rsp+28h] [rbp-60h]
int v42; // [rsp+30h] [rbp-58h]
int v43; // [rsp+34h] [rbp-54h]
unsigned int v44; // [rsp+38h] [rbp-50h]
unsigned int v45; // [rsp+3Ch] [rbp-4Ch]
__int64 v46; // [rsp+48h] [rbp-40h]
char Src; // [rsp+A0h] [rbp+18h] BYREF
char v48; // [rsp+A2h] [rbp+1Ah]
unsigned int v49; // [rsp+A8h] [rbp+20h] BYREF
v49 = 0;
v2 = cocos2d::CCFileUtils::sharedFileUtils();
result = ((__int64 (__fastcall *)(struct cocos2d::CCFileUtils *, __int64, const char *, unsigned int *))v2->addSearchResolutionsOrder)(
v2,
a1,
"rb",
&v49);
v46 = result;
v4 = result;
if ( result )
{
v5 = malloc(0x20u);
v6 = v49;
if ( v49 >= 3 )
{
v7 = *(_BYTE *)(v4 + 2);
v5[4] = v7;
if ( v6 >= 0x11 )
{
v8 = *(__int16 *)(v4 + 12);
v9 = *(__int16 *)(v4 + 14);
v10 = *(unsigned __int8 *)(v4 + 16);
*((_WORD *)v5 + 3) = *(_WORD *)(v4 + 12);
*((_WORD *)v5 + 4) = v9;
v5[5] = v10;
if ( v6 >= 0x12 )
{
v11 = (*(_BYTE *)(v4 + 17) & 0x20) == 0;
*((_DWORD *)v5 + 6) = 0;
if ( !v11 )
*((_DWORD *)v5 + 6) = 1;
if ( v7 == 1 )
{
*(_DWORD *)v5 = 3;
LABEL_42:
j_j_free_0((void *)v4);
return (__int64)v5;
}
if ( ((v7 - 2) & 0xF6) != 0 || v7 == 11 )
{
*(_DWORD *)v5 = 5;
goto LABEL_42;
}
v39 = v8;
v12 = v8;
v13 = v10 >> 3;
v14 = v9;
v43 = v9;
v41 = (char *)malloc((int)((v10 >> 3) * v9 * v8));
v15 = v41;
*((_QWORD *)v5 + 2) = v41;
if ( v41 )
{
v16 = v14 * v12;
v44 = v14 * v12;
if ( v7 == 10 )
{
v17 = v49;
v18 = 0;
v19 = 0;
v45 = v49;
v20 = 0;
v40 = 0;
v42 = 0;
v21 = 18;
if ( v16 )
{
v22 = v13;
while ( 1 )
{
v23 = v17;
if ( !v20 )
break;
--v20;
v24 = v22;
if ( !v18 )
goto LABEL_21;
LABEL_24:
memcpy(&v41[v19], &Src, v24);
v19 += v13;
v40 = v19;
v28 = ++v42 < v44;
v17 = v45;
v22 = v13;
if ( !v28 )
goto LABEL_25;
}
if ( v21 + 1 > (unsigned __int64)v17 )
goto LABEL_25;
v25 = *(_BYTE *)(v21 + v4);
v24 = v22;
++v21;
v18 = v25 & 0x80;
v20 = v25 + 0x80;
if ( (v25 & 0x80) == 0 )
v20 = v25;
LABEL_21:
v26 = v22 + v21;
if ( v22 + v21 > v23 )
goto LABEL_25;
memcpy(&Src, (const void *)(v21 + v4), v24);
v21 = v26;
v19 = v40;
if ( v13 >= 3 )
{
v27 = Src;
Src = v48;
v48 = v27;
}
goto LABEL_24;
}
LABEL_25:
v12 = v39;
v15 = v41;
}
else
{
v36 = (int)(v13 * v16);
if ( v36 + 18 > (unsigned __int64)v49 )
{
*(_DWORD *)v5 = 2;
goto LABEL_42;
}
memcpy(v41, (const void *)(v4 + 18), v36);
if ( v13 >= 3 && v36 > 0 )
{
for ( i = 0; i < v36; i += v13 )
{
v38 = v41[i];
v41[i] = v41[i + 2];
v41[i + 2] = v38;
}
}
}
v11 = *((_DWORD *)v5 + 6) == 0;
*(_DWORD *)v5 = 0;
if ( v11 )
goto LABEL_42;
v29 = v12 * v13;
v30 = malloc(v29);
if ( v30 )
{
v31 = v43;
v32 = 0;
if ( v43 / 2 > 0 )
{
v33 = 0;
do
{
v34 = &v15[v33];
memcpy(v30, v34, v29);
v35 = &v41[v29 * (v31 - v32 - 1)];
memcpy(v34, v35, v29);
memcpy(v35, v30, v29);
v15 = v41;
++v32;
v31 = v43;
v33 += v29;
}
while ( v32 < v43 / 2 );
v4 = v46;
}
free(v30);
*((_DWORD *)v5 + 6) = 0;
goto LABEL_42;
}
}
}
}
}
*(_DWORD *)v5 = 4;
goto LABEL_42;
}
return result;
}