//
// cocos2d::CCTextureCache::addImageAsync from 0x802a00 to 0x802c9e (670 bytes)
//
// 8 xrefs:
// > GameManager::loadBackgroundAsync @ 0x414790
// > GameManager::loadMiddlegroundAsync @ 0x414890
// > GameManager::loadMiddlegroundAsync @ 0x4148ba
// > GameManager::loadGroundAsync @ 0x414ab2
// > GameManager::loadGroundAsync @ 0x414ade
// > GameManager::loadIconAsync @ 0x41d94c
// > GJBigSprite::loadSpriteAsync @ 0x63f62e
// > cocos2d::CCTextureCache::prepareAsyncLoading @ 0x802cda
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:01:21 +0000
//
int __fastcall cocos2d::CCTextureCache::addImageAsync(
cocos2d::CCObject *a1,
char *a2,
int a3,
void (__fastcall *a4)(int, int),
int a5,
int a6,
int a7)
{
size_t v11; // r0
cocos2d::CCFileUtils *v12; // r0
int v13; // r1
char *v14; // r2
int v15; // r0
int v16; // r1
char *v17; // r2
char *v18; // r1
int v19; // r11
size_t v20; // r0
int v21; // r11
int *v22; // r0
int v23; // r0
_DWORD *v24; // r0
_DWORD *v25; // r0
int v26; // r0
int v27; // r0
_DWORD *v28; // r7
char *v29; // r1
_DWORD *v30; // r5
int v31; // r4
unsigned int v32; // r3
int v33; // r2
unsigned int v34; // r1
int v35; // r3
int v36; // r2
char *v38; // [sp+Ch] [bp-30h]
int v39; // [sp+1Ch] [bp-20h] BYREF
int v40; // [sp+20h] [bp-1Ch]
char *v41; // [sp+24h] [bp-18h]
int v42; // [sp+28h] [bp-14h] BYREF
int v43; // [sp+2Ch] [bp-10h]
char *v44; // [sp+30h] [bp-Ch]
v39 = 0;
v40 = 0;
v41 = nullptr;
v11 = strlen(a2);
v12 = (cocos2d::CCFileUtils *)std::string::__init(&v39, a2, v11);
v13 = cocos2d::CCFileUtils::sharedFileUtils(v12);
if ( (v39 & 1) != 0 )
v14 = v41;
else
v14 = (char *)&v39 + 1;
(*(void (__fastcall **)(int *, int, char *, _DWORD))(*(_DWORD *)v13 + 24))(&v42, v13, v14, 0);
if ( (v39 & 1) != 0 )
{
*v41 = 0;
v40 = 0;
}
else
{
LOWORD(v39) = 0;
}
std::string::reserve(&v39, 0);
v15 = v42;
v16 = v43;
v17 = v44;
v42 = 0;
v43 = 0;
v44 = nullptr;
v39 = v15;
v40 = v16;
v41 = v17;
std::string::~string((int)&v42);
v42 = 0;
v43 = 0;
if ( (v39 & 1) == 0 )
v18 = (char *)&v39 + 1;
v44 = nullptr;
if ( (v39 & 1) != 0 )
v18 = v41;
v19 = *((_DWORD *)a1 + 13);
v38 = v18;
v20 = strlen(v18);
std::string::__init(&v42, v38, v20);
v21 = cocos2d::CCDictionary::objectForKey(v19, (int)&v42);
std::string::~string((int)&v42);
v22 = std::string::basic_string(&v42, (int)&v39);
if ( v21 )
{
(*(void (__fastcall **)(int, int))(*(_DWORD *)v21 + 36))(v21, a6);
if ( a3 && (a4 || (a5 & 1) != 0) )
{
v23 = a5 >> 1;
if ( (a5 & 1) != 0 )
(*(void (__fastcall **)(int, int))((char *)a4 + *(_DWORD *)(a3 + v23)))(v23 + a3, v21);
else
a4(v23 + a3, v21);
}
std::string::~string((int)&v42);
}
else
{
if ( !dword_D31198 )
{
v24 = (_DWORD *)operator new(0x18u);
*v24 = 0;
v24[1] = 0;
v24[2] = 0;
v24[3] = 0;
v24[4] = 0;
v24[5] = 0;
dword_D31198 = (int)v24;
v25 = (_DWORD *)operator new(0x18u);
*v25 = 0;
v25[1] = 0;
v25[2] = 0;
v25[3] = 0;
v25[4] = 0;
v25[5] = 0;
dword_D3118C = (int)v25;
pthread_mutex_init((pthread_mutex_t *)&unk_D3119C, nullptr);
pthread_mutex_init((pthread_mutex_t *)&unk_D31190, nullptr);
pthread_mutex_init((pthread_mutex_t *)&unk_D311A0, nullptr);
pthread_cond_init((pthread_cond_t *)&unk_D31184, nullptr);
v22 = (int *)pthread_create(&dword_D311A4, nullptr, (void *(*)(void *))sub_801A04, nullptr);
byte_D31180 = 0;
}
if ( !dword_D31194 )
{
v26 = cocos2d::CCDirector::sharedDirector((cocos2d::CCDirector *)v22);
v27 = (*(int (__fastcall **)(int))(*(_DWORD *)v26 + 64))(v26);
cocos2d::CCScheduler::scheduleSelector(v27, (int)cocos2d::CCTextureCache::addImageAsyncCallBack, 0, a1, 0, 0);
}
++dword_D31194;
if ( a3 )
cocos2d::CCObject::retain(a3);
v28 = (_DWORD *)operator new(0x20u);
memset(v28, 0, 0x20u);
if ( (v42 & 1) != 0 )
v29 = v44;
else
v29 = (char *)&v42 + 1;
std::string::assign(v28, v29);
v28[3] = a3;
v28[4] = a4;
v28[6] = a6;
v28[5] = a5;
v28[7] = a7;
pthread_mutex_lock((pthread_mutex_t *)&unk_D3119C);
v30 = (_DWORD *)dword_D31198;
v31 = (v30[2] - v30[1]) >> 2;
if ( v31 )
v31 = (v31 << 10) - 1;
if ( v31 == *(_DWORD *)(dword_D31198 + 16) + *(_DWORD *)(dword_D31198 + 20) )
std::deque::__add_back_capacity(dword_D31198);
v32 = v30[4] + v30[5];
v33 = v30[1];
v34 = v32 >> 10;
if ( v30[2] != v33 )
{
v35 = v32 & 0x3FF;
v36 = *(_DWORD *)(v33 + 4 * v34);
if ( v36 + 4 * v35 )
*(_DWORD *)(v36 + 4 * v35) = v28;
}
++v30[5];
pthread_mutex_unlock((pthread_mutex_t *)&unk_D3119C);
pthread_cond_signal((pthread_cond_t *)&unk_D31184);
std::string::~string((int)&v42);
}
return std::string::~string((int)&v39);
}