//
// GameManager::unloadIcon from 0x100317d1c to 0x100317f14 (504 bytes)
//
// 2 xrefs:
// > GameManager::loadIcon @ 0x100317c40
// > GameManager::unloadIcons @ 0x1003180dc
//
// 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!
void __fastcall GameManager::unloadIcon(GameManager *a1, int a2, int a3, int a4)
{
__int64 v5; // x21
_QWORD *v7; // x0
cocos2d::CCTextureCache *v8; // x0
std::string *p_p; // x1
__int64 v10; // x0
std::string __p; // [xsp+0h] [xbp-60h] BYREF
std::string v12; // [xsp+18h] [xbp-48h] BYREF
int v13; // [xsp+34h] [xbp-2Ch] BYREF
int v14; // [xsp+38h] [xbp-28h] BYREF
int v15; // [xsp+3Ch] [xbp-24h] BYREF
v14 = a4;
v15 = a3;
if ( a2 >= 1 )
{
v5 = *(_QWORD *)&a2;
v13 = a2 + a1->m_keyStartForIcon.__begin_[a3] - 1;
v12.__r_.__value_.__r.__words[0] = (std::string::size_type)&v13;
v7 = sub_1001A6048((__int64)&a1->m_iconLoadCounts, &v13, (__int64)&unk_100644FD5, (unsigned int **)&v12);
--*((_DWORD *)v7 + 8);
if ( (_DWORD)v5 == 1 )
{
v12.__r_.__value_.__r.__words[0] = (std::string::size_type)&v13;
if ( *((int *)sub_1001A6048((__int64)&a1->m_iconLoadCounts, &v13, (__int64)&unk_100644FD5, (unsigned int **)&v12)
+ 8) <= 0 )
{
v12.__r_.__value_.__r.__words[0] = (std::string::size_type)&v13;
*((_DWORD *)sub_1001A6048((__int64)&a1->m_iconLoadCounts, &v13, (__int64)&unk_100644FD5, (unsigned int **)&v12)
+ 8) = 1;
}
}
v12.__r_.__value_.__r.__words[0] = (std::string::size_type)&v13;
if ( *((int *)sub_1001A6048((__int64)&a1->m_iconLoadCounts, &v13, (__int64)&unk_100644FD5, (unsigned int **)&v12) + 8) <= 0 )
{
GameManager::sheetNameForIcon(v5, a3, &v12);
if ( SHIBYTE(v12.__r_.__value_.__r.__words[2]) < 0 )
sub_1000097D0(&__p, v12.__r_.__value_.__l.__data_, v12.__r_.__value_.__l.__size_);
else
__p = v12;
std::string::append(&__p, ".png");
v8 = cocos2d::CCTextureCache::sharedTextureCache();
if ( (__p.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
p_p = &__p;
else
p_p = (std::string *)__p.__r_.__value_.__r.__words[0];
cocos2d::CCTextureCache::removeTextureForKey(v8, (const char *)p_p);
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
if ( SHIBYTE(v12.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v12.__r_.__value_.__l.__data_);
}
v12.__r_.__value_.__r.__words[0] = (std::string::size_type)&v14;
v10 = sub_10031E41C(&a1->m_iconRequests, &v14, &unk_100644FD5, &v12, &__p);
sub_10004C07C((_QWORD *)(v10 + 40), &v15);
v12.__r_.__value_.__r.__words[0] = (std::string::size_type)&v14;
if ( !*(_QWORD *)(sub_10031E41C(&a1->m_iconRequests, &v14, &unk_100644FD5, &v12, &__p) + 56) )
sub_10031E4E8(&a1->m_iconRequests, &v14);
}
}