//
// GameManager::loadIconAsync from 0x5fe57c to 0x5feae0 (1380 bytes)
//
// 2 xrefs:
// > SimplePlayer::asyncLoadIcon @ 0x792f18
// > ??> @ 0x58158
//
// 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
//
void GameManager::loadIconAsync(GameManager *a1, int a2, int a3, int a4, cocos2d::CCObject *a5)
{
__int64 v9; // x1
__int64 *v10; // x0
int v11; // w19
std::_rb_tree_base *m_parent; // x2
std::_rb_tree_base *p_m_header; // x24
__int64 v14; // x21
std::_rb_tree_base *v15; // x0
__int64 v16; // x0
__int64 v17; // x25
int *v18; // x28
int v19; // w27
void *v20; // x0
__int64 insert_unique_pos; // x21
__int64 v22; // x0
_DWORD *v23; // x25
int *v24; // x27
int v25; // w28
std::_rb_tree_base *m_left; // x2
int v27; // w0
_BOOL8 v28; // x0
cocos2d::CCTextureCache *v29; // x0
char *v30; // x0
unsigned int *v31; // x1
int v32; // w2
unsigned int *v33; // x1
int v34; // w2
unsigned int *v35; // x1
std::_rb_tree_base *m_right; // x2
int v37; // w0
_BOOL8 v38; // x0
std::_rb_tree_base *v39; // x1
std::_rb_tree_base *v40; // x1
__int64 v41; // [xsp+68h] [xbp+68h] BYREF
const char *v42; // [xsp+70h] [xbp+70h] BYREF
cocos2d::SEL_MenuHandler v43; // 0:x3.16
GameManager::sheetNameForIcon(a1, a2, a3, (__int64)&v41);
v9 = v41;
v10 = (__int64 *)(v41 - 24);
if ( *(_QWORD *)(v41 - 24) )
{
v11 = GameManager::keyForIcon(a1, a2, a3);
GameManager::addIconDelegate(a1, a5, v11);
m_parent = a1->m_isIconBeingLoaded.m_header.m_parent;
p_m_header = &a1->m_isIconBeingLoaded.m_header;
v14 = (__int64)&a1->m_isIconBeingLoaded.m_header;
v15 = m_parent;
if ( m_parent )
{
do
{
while ( v11 <= *(_DWORD *)&v15[1].m_isblack )
{
v14 = (__int64)v15;
v15 = v15->m_left;
if ( !v15 )
goto LABEL_7;
}
v15 = v15->m_right;
}
while ( v15 );
LABEL_7:
if ( p_m_header != (std::_rb_tree_base *)v14 && v11 >= *(_DWORD *)(v14 + 32) )
{
if ( *(_BYTE *)(v14 + 36) )
goto LABEL_37;
goto LABEL_42;
}
}
v16 = operator new(0x28u);
*(_DWORD *)(v16 + 32) = v11;
*(_BYTE *)(v16 + 36) = 0;
v17 = v16;
v18 = (int *)(v16 + 32);
if ( p_m_header == (std::_rb_tree_base *)v14 )
{
if ( a1->m_isIconBeingLoaded.m_nodecount )
{
m_right = a1->m_isIconBeingLoaded.m_header.m_right;
if ( v11 > *(_DWORD *)&m_right[1].m_isblack )
{
v14 = 0;
goto LABEL_60;
}
}
}
else
{
v19 = *(_DWORD *)(v14 + 32);
if ( v11 < v19 )
{
if ( a1->m_isIconBeingLoaded.m_header.m_left == (std::_rb_tree_base *)v14 )
{
m_right = (std::_rb_tree_base *)v14;
goto LABEL_60;
}
m_right = (std::_rb_tree_base *)sub_CFABD4(v14);
if ( v11 > *(_DWORD *)&m_right[1].m_isblack )
{
if ( m_right->m_right )
m_right = (std::_rb_tree_base *)v14;
else
v14 = 0;
goto LABEL_60;
}
}
else
{
if ( v11 <= v19 )
{
LABEL_12:
v20 = (void *)v17;
v17 = v14;
operator delete(v20);
goto LABEL_13;
}
if ( a1->m_isIconBeingLoaded.m_header.m_right == (std::_rb_tree_base *)v14 )
{
m_right = (std::_rb_tree_base *)v14;
LABEL_62:
v37 = *(_DWORD *)(v17 + 32);
v19 = *(_DWORD *)&m_right[1].m_isblack;
LABEL_63:
v38 = v37 < v19;
LABEL_64:
sub_CFAD74(v38, v17, m_right, &a1->m_isIconBeingLoaded.m_header);
++a1->m_isIconBeingLoaded.m_nodecount;
LABEL_13:
if ( *(_BYTE *)(v17 + 36) )
goto LABEL_37;
m_parent = a1->m_isIconBeingLoaded.m_header.m_parent;
if ( !m_parent )
{
insert_unique_pos = (__int64)&a1->m_isIconBeingLoaded.m_header;
goto LABEL_16;
}
LABEL_42:
insert_unique_pos = (__int64)&a1->m_isIconBeingLoaded.m_header;
do
{
while ( v11 <= *(_DWORD *)&m_parent[1].m_isblack )
{
insert_unique_pos = (__int64)m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_45;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_45:
if ( p_m_header != (std::_rb_tree_base *)insert_unique_pos && v11 >= *(_DWORD *)(insert_unique_pos + 32) )
goto LABEL_28;
LABEL_16:
v22 = operator new(0x28u);
*(_DWORD *)(v22 + 32) = v11;
*(_BYTE *)(v22 + 36) = 0;
v23 = (_DWORD *)v22;
v24 = (int *)(v22 + 32);
if ( p_m_header == (std::_rb_tree_base *)insert_unique_pos )
{
if ( a1->m_isIconBeingLoaded.m_nodecount )
{
m_left = a1->m_isIconBeingLoaded.m_header.m_right;
if ( v11 > *(_DWORD *)&m_left[1].m_isblack )
{
insert_unique_pos = 0;
goto LABEL_23;
}
}
}
else
{
v25 = *(_DWORD *)(insert_unique_pos + 32);
if ( v11 < v25 )
{
m_left = a1->m_isIconBeingLoaded.m_header.m_left;
if ( (std::_rb_tree_base *)insert_unique_pos == m_left )
goto LABEL_23;
m_left = (std::_rb_tree_base *)sub_CFABD4(insert_unique_pos);
if ( v11 > *(_DWORD *)&m_left[1].m_isblack )
{
if ( m_left->m_right )
m_left = (std::_rb_tree_base *)insert_unique_pos;
else
insert_unique_pos = 0;
goto LABEL_23;
}
goto LABEL_77;
}
if ( v11 <= v25 )
{
LABEL_76:
operator delete(v23);
LABEL_28:
*(_BYTE *)(insert_unique_pos + 36) = 1;
sub_D18D28(&v42, &v41);
sub_D15FD4(&v42, ".png", 4);
v29 = cocos2d::CCTextureCache::sharedTextureCache();
v43.adj = 0;
v43.ptr = (void (__cdecl *)(cocos2d::CCObject *))GameManager::finishedLoadingIconAsync;
cocos2d::CCTextureCache::addImageAsync(v29, v42, a1, v43, v11, kCCTexture2DPixelFormat_RGBA8888);
v30 = (char *)(v42 - 24);
if ( v42 - 24 != (const char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v31 = (unsigned int *)(v42 - 8);
do
v32 = __ldaxr(v31);
while ( __stlxr(v32 - 1, v31) );
}
else
{
v32 = *((_DWORD *)v42 - 2);
*((_DWORD *)v42 - 2) = v32 - 1;
}
if ( v32 <= 0 )
operator delete(v30);
}
LABEL_37:
v9 = v41;
v10 = (__int64 *)(v41 - 24);
if ( (__int64 *)(v41 - 24) == &qword_124B6B0 )
return;
if ( &pthread_create )
{
v33 = (unsigned int *)(v41 - 8);
do
v34 = __ldaxr(v33);
while ( __stlxr(v34 - 1, v33) );
goto LABEL_53;
}
goto LABEL_65;
}
if ( (std::_rb_tree_base *)insert_unique_pos == a1->m_isIconBeingLoaded.m_header.m_right )
{
LABEL_91:
v27 = v11;
m_left = (std::_rb_tree_base *)insert_unique_pos;
goto LABEL_26;
}
m_left = (std::_rb_tree_base *)sub_CFAB14(insert_unique_pos);
if ( v11 < *(_DWORD *)&m_left[1].m_isblack )
{
if ( *(_QWORD *)(insert_unique_pos + 24) )
{
insert_unique_pos = (__int64)m_left;
goto LABEL_23;
}
goto LABEL_91;
}
}
LABEL_77:
insert_unique_pos = std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_get_insert_unique_pos(
(__int64)&a1->m_isIconBeingLoaded,
v24);
m_left = v40;
if ( !v40 )
goto LABEL_76;
LABEL_23:
if ( insert_unique_pos || p_m_header == m_left )
{
v28 = 1;
goto LABEL_27;
}
v27 = v23[8];
v25 = *(_DWORD *)&m_left[1].m_isblack;
LABEL_26:
v28 = v25 > v27;
LABEL_27:
insert_unique_pos = (__int64)v23;
sub_CFAD74(v28, v23, m_left, &a1->m_isIconBeingLoaded.m_header);
++a1->m_isIconBeingLoaded.m_nodecount;
goto LABEL_28;
}
m_right = (std::_rb_tree_base *)sub_CFAB14(v14);
if ( v11 < *(_DWORD *)&m_right[1].m_isblack )
{
if ( !*(_QWORD *)(v14 + 24) )
{
v37 = v11;
m_right = (std::_rb_tree_base *)v14;
goto LABEL_63;
}
v14 = (__int64)m_right;
goto LABEL_60;
}
}
}
v14 = std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_get_insert_unique_pos(
(__int64)&a1->m_isIconBeingLoaded,
v18);
m_right = v39;
if ( !v39 )
goto LABEL_12;
LABEL_60:
if ( v14 || p_m_header == m_right )
{
v38 = 1;
goto LABEL_64;
}
goto LABEL_62;
}
if ( v10 == &qword_124B6B0 )
return;
if ( &pthread_create )
{
v35 = (unsigned int *)(v41 - 8);
do
v34 = __ldaxr(v35);
while ( __stlxr(v34 - 1, v35) );
goto LABEL_53;
}
LABEL_65:
v34 = *(_DWORD *)(v9 - 8);
*(_DWORD *)(v9 - 8) = v34 - 1;
LABEL_53:
if ( v34 <= 0 )
operator delete(v10);
}