//
// LevelSearchLayer::toggleDifficulty from 0x6cf034 to 0x6cf3b8 (900 bytes)
//
// 3 xrefs:
// > ??> @ 0xa9038
// > LevelSearchLayer::init @ 0x6d26c4
// > ??> @ 0x122dda0
//
// 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 LevelSearchLayer::toggleDifficulty(LevelSearchLayer *a1, cocos2d::CCObject *a2)
{
int v3; // w21
unsigned int v4; // w27
int v5; // w25
cocos2d::CCDictionary *m_difficultyDict; // x23
cocos2d::CCObject *v7; // x20
char *DiffKey; // x0
char *v9; // x0
__int64 v10; // x0
char v11; // w2
void (__fastcall *v12)(__int64, std::string *); // x3
int j; // w20
int v14; // w1
GameLevelManager *v15; // x0
cocos2d::CCDictionary *v16; // x20
char *v17; // x0
cocos2d::CCString *v18; // x0
_BOOL4 v19; // w20
char *v20; // x22
int k; // w20
int v22; // w1
int m; // w20
int v24; // w1
int i; // w20
unsigned int *v26; // x21
int v27; // w0
unsigned int *v28; // x1
int v29; // w2
std::string v30; // [xsp+70h] [xbp+70h] BYREF
v3 = a2->getTag(a2);
v4 = LevelSearchLayer::checkDiff(a1, v3);
if ( a1->m_type == 1 )
{
for ( i = 0; i != 8; ++i )
{
if ( i != v3 )
LevelSearchLayer::toggleDifficultyNum(a1, i, 0);
}
}
v5 = v4 ^ 1;
m_difficultyDict = a1->m_difficultyDict;
v7 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", (const char *)(v4 ^ 1));
DiffKey = (char *)LevelSearchLayer::getDiffKey(a1, v3);
sub_D153B8((int)&v30, DiffKey);
cocos2d::CCDictionary::setObject((int)m_difficultyDict, v7);
v9 = (char *)v30.m_data.m_data - 24;
if ( (__int64 *)v30.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v28 = (unsigned int *)((char *)v30.m_data.m_data - 8);
do
v29 = __ldaxr(v28);
while ( __stlxr(v29 - 1, v28) );
}
else
{
v29 = *((_DWORD *)v30.m_data.m_data - 2);
*((_DWORD *)v30.m_data.m_data - 2) = v29 - 1;
}
if ( v29 <= 0 )
operator delete(v9);
}
v10 = cocos2d::CCArray::objectAtIndex(a1->m_difficultySprites, v3);
v11 = -1;
if ( !v5 )
v11 = 125;
v12 = *(void (__fastcall **)(__int64, std::string *))(*(_QWORD *)v10 + 944LL);
LOBYTE(v30.m_data.m_data) = v11;
BYTE1(v30.m_data.m_data) = v11;
BYTE2(v30.m_data.m_data) = v11;
v12(v10, &v30);
if ( (v3 == 0) > v4 )
{
for ( j = 1; j != 8; ++j )
{
v14 = j;
LevelSearchLayer::toggleDifficultyNum(a1, v14, 0);
}
goto LABEL_8;
}
if ( (v3 == 6) > v4 )
{
for ( k = 0; k != 6; ++k )
{
v22 = k;
LevelSearchLayer::toggleDifficultyNum(a1, v22, 0);
}
goto LABEL_13;
}
if ( (v3 == 7) <= v4 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 0, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 6, 0);
LABEL_13:
LevelSearchLayer::toggleDifficultyNum(a1, 7, 0);
goto LABEL_8;
}
for ( m = 0; m != 7; ++m )
{
v24 = m;
LevelSearchLayer::toggleDifficultyNum(a1, v24, 0);
}
LABEL_8:
v15 = GameLevelManager::sharedState();
GameLevelManager::setDiffVal(v15, v3, v5);
v16 = a1->m_difficultyDict;
v17 = (char *)LevelSearchLayer::getDiffKey(a1, 6);
sub_D153B8((int)&v30, v17);
v18 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v16, &v30);
v19 = cocos2d::CCString::boolValue(v18);
v20 = (char *)v30.m_data.m_data - 24;
if ( (__int64 *)v30.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v26 = (unsigned int *)((char *)v30.m_data.m_data - 8);
do
v27 = __ldaxr(v26);
while ( __stlxr(v27 - 1, v26) );
}
else
{
v27 = *((_DWORD *)v30.m_data.m_data - 2);
*((_DWORD *)v30.m_data.m_data - 2) = v27 - 1;
}
if ( v27 <= 0 )
operator delete(v20);
}
a1->m_demonTypeButton->setEnabled(a1->m_demonTypeButton, v19);
a1->m_demonTypeButton->setVisible(a1->m_demonTypeButton, v19);
}