//
// GameManager::loadIcon from 0x100381eb0 to 0x1003824b8 (1544 bytes)
//
// 14 xrefs:
// > SimplePlayer::updatePlayerFrame @ 0x10036b12d
// > SimplePlayer::init @ 0x100370330
// > GameManager::finishedLoadingIconAsync @ 0x100381b2a
// > PlayerObject::init @ 0x1003fa757
// > PlayerObject::init @ 0x1003fa776
// > PlayerObject::updatePlayerShipFrame @ 0x1004166e9
// > PlayerObject::updatePlayerJetpackFrame @ 0x100416936
// > PlayerObject::updatePlayerBirdFrame @ 0x1004171e9
// > PlayerObject::updatePlayerSwingFrame @ 0x1004178d6
// > PlayerObject::updatePlayerFrame @ 0x100417ba9
// > PlayerObject::updatePlayerDartFrame @ 0x1004182f6
// > PlayerObject::updatePlayerRollFrame @ 0x1004186e2
// > GJRobotSprite::init @ 0x1005dbe47
// > GJRobotSprite::updateFrame @ 0x1005dc3f7
//
// 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
//
// local variable allocation has failed, the output may be wrong!
cocos2d::CCTexture2D *__fastcall GameManager::loadIcon(GameManager *a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
int v5; // ebx
std::__compressed_pair *>> *p_pair1; // rbx
std::__tree_end_node *>::pointer left; // rax
std::__compressed_pair *>> *v8; // r14
int v9; // eax
_DWORD *v10; // r13
GameManager *v11; // rbx
std::__tree_end_node *> *v12; // rax
cocos2d::CCTextureCache *v13; // rax
const char *v14; // rsi
cocos2d::CCTexture2D *v15; // rbx
std::__compressed_pair *>> *v16; // r13
cocos2d::CCTextureCache *v17; // rax
const char *data; // rsi
cocos2d::CCTexture2D *v19; // r14
cocos2d::CCSpriteFrameCache *v20; // rax
const char *v21; // rsi
std::__compressed_pair *>> *v22; // r14
std::__tree_end_node *>::pointer v23; // rax
std::__compressed_pair *>> *v24; // r12
std::__compressed_pair *>> *v25; // rbx
char *v26; // r13
GameManager *v27; // rbx
std::__tree_end_node *> *v28; // rax
__int64 *v29; // rax
_QWORD *v30; // r15
_QWORD *v31; // rbx
_DWORD *v32; // r12
__int64 v33; // rax
std::__compressed_pair *>> *v34; // rcx
int v35; // r12d
std::__tree_end_node *>::pointer v37; // rax
std::__compressed_pair *>> *v38; // rbx
int v39; // eax
std::__compressed_pair *>> *v40; // r15
_DWORD *v41; // r13
GameManager *v42; // rbx
std::__tree_end_node *> *v43; // rax
std::__compressed_pair *>> *v44; // rax
std::__compressed_pair *>> *v45; // rbx
char *v46; // r13
GameManager *v47; // rbx
std::__tree_end_node *> *v48; // rax
__int64 *v49; // rax
_QWORD *v50; // r15
_QWORD *v51; // r14
_DWORD *v52; // rbx
__int64 v53; // rax
std::__compressed_pair *>> *v54; // [rsp+0h] [rbp-B0h]
cocos2d::CCTexture2D *v55; // [rsp+8h] [rbp-A8h]
std::string v56; // [rsp+10h] [rbp-A0h] BYREF
std::string v57; // [rsp+30h] [rbp-80h] BYREF
__int128 v58; // [rsp+50h] [rbp-60h] BYREF
void *__p; // [rsp+60h] [rbp-50h]
__int64 v60; // [rsp+68h] [rbp-48h]
GameManager *v61; // [rsp+70h] [rbp-40h]
int v62; // [rsp+7Ch] [rbp-34h]
int v63; // [rsp+80h] [rbp-30h]
int v64; // [rsp+84h] [rbp-2Ch]
v62 = a4;
v60 = (unsigned int)a2;
v64 = a3;
GameManager::sheetNameForIcon((size_t *)&v58, *(__int64 *)&a2, a2, a3);
v61 = a1;
if ( (v58 & 1) != 0 )
{
if ( !*((_QWORD *)&v58 + 1) )
{
v15 = nullptr;
if ( (v58 & 1) == 0 )
return v15;
goto LABEL_60;
}
v5 = a1->m_keyStartForIcon.__begin_[v64];
sub_100006B70(&v57, __p, *((unsigned __int64 *)&v58 + 1), v4);
v63 = v5 + v60 - 1;
}
else
{
if ( !(_BYTE)v58 )
return nullptr;
v63 = v60 + a1->m_keyStartForIcon.__begin_[v64] - 1;
v57.__r_.__value_.__r.__words[2] = (std::string::size_type)__p;
v4 = *(double *)&v58;
*(_OWORD *)&v57.__r_.__value_.__l.0 = v58;
}
std::string::append(&v57, ".png");
p_pair1 = &v61->m_iconLoadCounts.__tree_.__pair1_;
left = v61->m_iconLoadCounts.__tree_.__pair1_.__value_.__left_;
v8 = &v61->m_iconLoadCounts.__tree_.__pair1_;
v54 = &v61->m_iconLoadCounts.__tree_.__pair1_;
LABEL_8:
if ( left )
{
while ( 1 )
{
p_pair1 = (std::__compressed_pair *>> *)left;
v9 = *((_DWORD *)left + 7);
if ( v63 < v9 )
{
left = p_pair1->__value_.__left_;
v8 = p_pair1;
goto LABEL_8;
}
if ( v63 <= v9 )
break;
left = p_pair1[1].__value_.__left_;
if ( !left )
{
v8 = p_pair1 + 1;
goto LABEL_13;
}
}
v16 = p_pair1;
v11 = v61;
if ( SLODWORD(v16[4].__value_.__left_) <= 0 )
goto LABEL_24;
}
else
{
LABEL_13:
v10 = operator new(0x28u);
v10[7] = v63;
v10[8] = 0;
v4 = 0.0;
*(_OWORD *)v10 = 0;
*((_QWORD *)v10 + 2) = p_pair1;
v8->__value_.__left_ = (std::__tree_end_node *>::pointer)v10;
v11 = v61;
v12 = (std::__tree_end_node *> *)v61->m_iconLoadCounts.__tree_.__begin_node_->__left_;
if ( v12 )
v61->m_iconLoadCounts.__tree_.__begin_node_ = v12;
sub_100054DD0((__int64 *)v11->m_iconLoadCounts.__tree_.__pair1_.__value_.__left_, (__int64 *)v10);
++v11->m_iconLoadCounts.__tree_.__pair3_.__value_;
if ( (int)v10[8] <= 0 )
{
LABEL_24:
if ( (v58 & 1) != 0 )
{
sub_100006B70(&v56, __p, *((unsigned __int64 *)&v58 + 1), v4);
}
else
{
v56.__r_.__value_.__r.__words[2] = (std::string::size_type)__p;
*(_OWORD *)&v56.__r_.__value_.__l.0 = v58;
}
std::string::append(&v56, ".plist");
v17 = cocos2d::CCTextureCache::sharedTextureCache();
if ( (*(_BYTE *)&v57.__r_.__value_.__s.0 & 1) != 0 )
data = v57.__r_.__value_.__l.__data_;
else
data = v57.__r_.__value_.__s.__data_;
v19 = cocos2d::CCTextureCache::addImage(v17, data, 0);
v20 = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache();
if ( (*(_BYTE *)&v56.__r_.__value_.__s.0 & 1) != 0 )
v21 = v56.__r_.__value_.__l.__data_;
else
v21 = v56.__r_.__value_.__s.__data_;
cocos2d::CCSpriteFrameCache::addSpriteFramesWithFile_2(v20, v21);
if ( (*(_BYTE *)&v56.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v56.__r_.__value_.__l.__data_);
v55 = v19;
goto LABEL_36;
}
}
v13 = cocos2d::CCTextureCache::sharedTextureCache();
if ( (*(_BYTE *)&v57.__r_.__value_.__s.0 & 1) != 0 )
v14 = v57.__r_.__value_.__l.__data_;
else
v14 = v57.__r_.__value_.__s.__data_;
v55 = cocos2d::CCTextureCache::textureForKey(v13, v14);
v11 = v61;
LABEL_36:
v22 = &v11->m_iconRequests.__tree_.__pair1_;
v23 = v11->m_iconRequests.__tree_.__pair1_.__value_.__left_;
v24 = &v11->m_iconRequests.__tree_.__pair1_;
v25 = &v11->m_iconRequests.__tree_.__pair1_;
LABEL_38:
if ( v23 )
{
while ( 1 )
{
v25 = (std::__compressed_pair *>> *)v23;
if ( *((_DWORD *)v23 + 8) > v62 )
{
v23 = *(std::__tree_end_node *>::pointer *)v23;
v24 = v25;
goto LABEL_38;
}
if ( *((_DWORD *)v23 + 8) >= v62 )
break;
v23 = *((std::__tree_end_node *>::pointer *)v23 + 1);
if ( !v23 )
{
v24 = v25 + 1;
goto LABEL_43;
}
}
v26 = (char *)v23;
v29 = *((__int64 **)v23 + 6);
if ( v29 )
goto LABEL_50;
LABEL_48:
v30 = v26 + 48;
v31 = v26 + 48;
LABEL_54:
v32 = operator new(0x28u);
v32[7] = v64;
v32[8] = 0;
*(_OWORD *)v32 = 0;
*((_QWORD *)v32 + 2) = v31;
*v30 = v32;
v33 = **((_QWORD **)v26 + 5);
if ( v33 )
*((_QWORD *)v26 + 5) = v33;
sub_100054DD0(*((__int64 **)v26 + 6), (__int64 *)v32);
++*((_QWORD *)v26 + 7);
v34 = v54;
v35 = v32[8];
if ( v35 == (_DWORD)v60 )
goto LABEL_57;
goto LABEL_63;
}
LABEL_43:
v26 = (char *)operator new(0x40u);
*((_DWORD *)v26 + 8) = v62;
*((_OWORD *)v26 + 3) = 0;
*((_QWORD *)v26 + 5) = v26 + 48;
*(_OWORD *)v26 = 0;
*((_QWORD *)v26 + 2) = v25;
v24->__value_.__left_ = (std::__tree_end_node *>::pointer)v26;
v27 = v61;
v28 = (std::__tree_end_node *> *)v61->m_iconRequests.__tree_.__begin_node_->__left_;
if ( v28 )
v61->m_iconRequests.__tree_.__begin_node_ = v28;
sub_100054DD0((__int64 *)v27->m_iconRequests.__tree_.__pair1_.__value_.__left_, (__int64 *)v26);
++v27->m_iconRequests.__tree_.__pair3_.__value_;
v29 = *((__int64 **)v26 + 6);
if ( !v29 )
goto LABEL_48;
while ( 1 )
{
LABEL_50:
while ( 1 )
{
v31 = v29;
if ( *((_DWORD *)v29 + 7) <= v64 )
break;
v29 = (__int64 *)*v29;
v30 = v31;
if ( !*v31 )
goto LABEL_54;
}
if ( *((_DWORD *)v29 + 7) >= v64 )
break;
v29 = (__int64 *)v29[1];
if ( !v29 )
{
v30 = v31 + 1;
goto LABEL_54;
}
}
v34 = v54;
v35 = *((_DWORD *)v29 + 8);
if ( v35 == (_DWORD)v60 )
{
LABEL_57:
if ( (*(_BYTE *)&v57.__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_59;
goto LABEL_58;
}
LABEL_63:
v37 = v34->__value_.__left_;
v38 = v34;
LABEL_65:
if ( !v37 )
{
LABEL_70:
v40 = v34;
v41 = operator new(0x28u);
v41[7] = v63;
v41[8] = 0;
*(_OWORD *)v41 = 0;
*((_QWORD *)v41 + 2) = v38;
v40->__value_.__left_ = (std::__tree_end_node *>::pointer)v41;
v42 = v61;
v43 = (std::__tree_end_node *> *)v61->m_iconLoadCounts.__tree_.__begin_node_->__left_;
if ( v43 )
v61->m_iconLoadCounts.__tree_.__begin_node_ = v43;
sub_100054DD0((__int64 *)v42->m_iconLoadCounts.__tree_.__pair1_.__value_.__left_, (__int64 *)v41);
++v42->m_iconLoadCounts.__tree_.__pair3_.__value_;
++v41[8];
if ( v35 <= 0 )
goto LABEL_76;
goto LABEL_75;
}
while ( 1 )
{
v38 = (std::__compressed_pair *>> *)v37;
v39 = *((_DWORD *)v37 + 7);
if ( v63 < v39 )
{
v37 = v38->__value_.__left_;
v34 = v38;
goto LABEL_65;
}
if ( v63 <= v39 )
break;
v37 = v38[1].__value_.__left_;
if ( !v37 )
{
v34 = v38 + 1;
goto LABEL_70;
}
}
++LODWORD(v38[4].__value_.__left_);
if ( v35 > 0 )
LABEL_75:
GameManager::unloadIcon(v61, v35, v64, v62);
LABEL_76:
v44 = (std::__compressed_pair *>> *)v22->__value_.__left_;
v45 = v22;
LABEL_78:
if ( v44 )
{
while ( 1 )
{
v45 = v44;
if ( SLODWORD(v44[4].__value_.__left_) > v62 )
{
v44 = (std::__compressed_pair *>> *)v44->__value_.__left_;
v22 = v45;
goto LABEL_78;
}
if ( SLODWORD(v44[4].__value_.__left_) >= v62 )
break;
v44 = (std::__compressed_pair *>> *)v44[1].__value_.__left_;
if ( !v44 )
{
v22 = v45 + 1;
goto LABEL_83;
}
}
v46 = (char *)v44;
v49 = (__int64 *)v44[6].__value_.__left_;
if ( v49 )
goto LABEL_90;
goto LABEL_88;
}
LABEL_83:
v46 = (char *)operator new(0x40u);
*((_DWORD *)v46 + 8) = v62;
*((_OWORD *)v46 + 3) = 0;
*((_QWORD *)v46 + 5) = v46 + 48;
*(_OWORD *)v46 = 0;
*((_QWORD *)v46 + 2) = v45;
v22->__value_.__left_ = (std::__tree_end_node *>::pointer)v46;
v47 = v61;
v48 = (std::__tree_end_node *> *)v61->m_iconRequests.__tree_.__begin_node_->__left_;
if ( v48 )
v61->m_iconRequests.__tree_.__begin_node_ = v48;
sub_100054DD0((__int64 *)v47->m_iconRequests.__tree_.__pair1_.__value_.__left_, (__int64 *)v46);
++v47->m_iconRequests.__tree_.__pair3_.__value_;
v49 = *((__int64 **)v46 + 6);
if ( !v49 )
{
LABEL_88:
v50 = v46 + 48;
v51 = v46 + 48;
LABEL_94:
v52 = operator new(0x28u);
v52[7] = v64;
v52[8] = 0;
*(_OWORD *)v52 = 0;
*((_QWORD *)v52 + 2) = v51;
*v50 = v52;
v53 = **((_QWORD **)v46 + 5);
if ( v53 )
*((_QWORD *)v46 + 5) = v53;
sub_100054DD0(*((__int64 **)v46 + 6), (__int64 *)v52);
++*((_QWORD *)v46 + 7);
goto LABEL_98;
}
while ( 1 )
{
LABEL_90:
while ( 1 )
{
v51 = v49;
if ( *((_DWORD *)v49 + 7) <= v64 )
break;
v49 = (__int64 *)*v49;
v50 = v51;
if ( !*v51 )
goto LABEL_94;
}
if ( *((_DWORD *)v49 + 7) >= v64 )
break;
v49 = (__int64 *)v49[1];
if ( !v49 )
{
v50 = v51 + 1;
goto LABEL_94;
}
}
v52 = v49;
LABEL_98:
v52[8] = v60;
if ( (*(_BYTE *)&v57.__r_.__value_.__s.0 & 1) != 0 )
LABEL_58:
operator delete(v57.__r_.__value_.__l.__data_);
LABEL_59:
v15 = v55;
if ( (v58 & 1) != 0 )
LABEL_60:
operator delete(__p);
return v15;
}