//
// LevelSearchLayer::toggleDifficulty from 0x10062ae00 to 0x10062b2bd (1213 bytes)
//
// 8 xrefs:
// > LevelSearchLayer::init @ 0x100629222
// > LevelSearchLayer::init @ 0x1006292cb
// > LevelSearchLayer::init @ 0x100629377
// > LevelSearchLayer::init @ 0x100629423
// > LevelSearchLayer::init @ 0x1006294cf
// > LevelSearchLayer::init @ 0x10062957b
// > LevelSearchLayer::init @ 0x100629627
// > LevelSearchLayer::init @ 0x1006296e2
//
// 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 __fastcall LevelSearchLayer::toggleDifficulty(LevelSearchLayer *a1, cocos2d::CCObject *a2)
{
double v2; // xmm0_8
int v3; // r15d
bool v4; // r14
bool v5; // r13
char v6; // al
cocos2d::CCString *v7; // rax
const char *CString; // r14
size_t v9; // rax
size_t v10; // r12
char *v11; // r13
size_t v12; // r15
__int64 v13; // rax
int v14; // r12d
int v15; // r15d
int v16; // esi
GameLevelManager *v17; // rax
cocos2d::CCDictionary *v18; // r14
cocos2d::CCString *v19; // rax
const char *v20; // r12
size_t v21; // rax
size_t v22; // r15
char *v23; // r13
size_t v24; // r14
cocos2d::CCString *v25; // rax
bool v26; // r14
char v27; // [rsp+0h] [rbp-60h]
cocos2d::CCObject *v28; // [rsp+0h] [rbp-60h]
unsigned int v29; // [rsp+8h] [rbp-58h]
bool v30; // [rsp+Ch] [rbp-54h]
cocos2d::CCDictionary *m_difficultyDict; // [rsp+10h] [rbp-50h]
cocos2d::CCDictionary *v32; // [rsp+10h] [rbp-50h]
size_t __dst; // [rsp+18h] [rbp-48h] BYREF
size_t v34; // [rsp+20h] [rbp-40h]
void *__p; // [rsp+28h] [rbp-38h]
bool v36; // [rsp+37h] [rbp-29h]
v3 = ((__int64 (__fastcall *)(cocos2d::CCObject *))a2->getTag)(a2);
v4 = LevelSearchLayer::checkDiff(a1, v3);
if ( a1->m_type == 1 )
{
if ( v3 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 0, 0);
if ( v3 != 1 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 1, 0);
if ( v3 != 2 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 2, 0);
if ( v3 != 3 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 3, 0);
if ( v3 != 4 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 4, 0);
if ( v3 != 5 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 5, 0);
if ( v3 != 6 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 6, 0);
if ( v3 == 7 )
goto LABEL_18;
}
LABEL_17:
LevelSearchLayer::toggleDifficultyNum(a1, 7, 0);
goto LABEL_18;
}
LABEL_16:
LevelSearchLayer::toggleDifficultyNum(a1, 6, 0);
goto LABEL_17;
}
LABEL_15:
LevelSearchLayer::toggleDifficultyNum(a1, 5, 0);
goto LABEL_16;
}
LABEL_14:
LevelSearchLayer::toggleDifficultyNum(a1, 4, 0);
goto LABEL_15;
}
LABEL_13:
LevelSearchLayer::toggleDifficultyNum(a1, 3, 0);
goto LABEL_14;
}
}
else
{
LevelSearchLayer::toggleDifficultyNum(a1, 1, 0);
}
LevelSearchLayer::toggleDifficultyNum(a1, 2, 0);
goto LABEL_13;
}
LABEL_18:
v36 = v4;
m_difficultyDict = a1->m_difficultyDict;
v5 = !v4;
v6 = sub_1007AB580("%i", v27);
v7 = (cocos2d::CCString *)sub_1007AB580("D%i", v6);
CString = cocos2d::CCString::getCString(v7);
v9 = strlen(CString);
if ( v9 >= 0xFFFFFFFFFFFFFFF8LL )
goto LABEL_48;
v10 = v9;
v30 = v5;
v29 = v3;
if ( v9 >= 0x17 )
{
v12 = 26;
if ( (v9 | 7) != 0x17 )
v12 = (v9 | 7) + 1;
v11 = (char *)operator new(v12);
__p = v11;
__dst = v12 + 1;
v34 = v10;
goto LABEL_25;
}
LOBYTE(__dst) = 2 * v9;
v11 = (char *)&__dst + 1;
if ( v9 )
LABEL_25:
memmove(v11, CString, v10);
v11[v10] = 0;
cocos2d::CCDictionary::setObject_1((__int64)m_difficultyDict, v28, (char *)&__dst);
if ( (__dst & 1) != 0 )
operator delete(__p);
v13 = sub_1007200C0(a1->m_difficultySprites, v29);
if ( v36 )
{
memset(&__dst, 125, 3);
(*(void (__fastcall **)(__int64, size_t *))(*(_QWORD *)v13 + 944LL))(v13, &__dst);
v14 = 7;
v15 = 6;
v16 = 0;
goto LABEL_37;
}
BYTE2(__dst) = -1;
LOWORD(__dst) = -1;
(*(void (__fastcall **)(__int64, size_t *))(*(_QWORD *)v13 + 944LL))(v13, &__dst);
if ( v29 == 7 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 0, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 1, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 2, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 3, 0);
v14 = 6;
goto LABEL_36;
}
v14 = 7;
if ( v29 == 6 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 0, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 1, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 2, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 3, 0);
LABEL_36:
v15 = 5;
v16 = 4;
goto LABEL_37;
}
v15 = 6;
v16 = 0;
if ( !v29 )
{
LevelSearchLayer::toggleDifficultyNum(a1, 1, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 2, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 3, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 4, 0);
v16 = 5;
}
LABEL_37:
LevelSearchLayer::toggleDifficultyNum(a1, v16, 0);
LevelSearchLayer::toggleDifficultyNum(a1, v15, 0);
LevelSearchLayer::toggleDifficultyNum(a1, v14, 0);
v17 = GameLevelManager::sharedState();
GameLevelManager::setDiffVal(v17, v29, v30);
v18 = a1->m_difficultyDict;
v19 = (cocos2d::CCString *)sub_1007AB580("D%i", (char)v28);
v20 = cocos2d::CCString::getCString(v19);
v21 = strlen(v20);
if ( v21 >= 0xFFFFFFFFFFFFFFF8LL )
LABEL_48:
sub_100006BF0(v2);
v22 = v21;
if ( v21 >= 0x17 )
{
v32 = v18;
v24 = 26;
if ( (v21 | 7) != 0x17 )
v24 = (v21 | 7) + 1;
v23 = (char *)operator new(v24);
__p = v23;
__dst = v24 + 1;
v18 = v32;
v34 = v22;
goto LABEL_44;
}
LOBYTE(__dst) = 2 * v21;
v23 = (char *)&__dst + 1;
if ( v21 )
LABEL_44:
memmove(v23, v20, v22);
v23[v22] = 0;
v25 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey_1((__int64)v18, (__int64)&__dst);
v26 = cocos2d::CCString::boolValue(v25);
if ( (__dst & 1) != 0 )
operator delete(__p);
((void (__fastcall *)(CCMenuItemSpriteExtra *, bool))a1->m_demonTypeButton->setEnabled)(a1->m_demonTypeButton, v26);
((void (__fastcall *)(CCMenuItemSpriteExtra *, bool))a1->m_demonTypeButton->setVisible)(a1->m_demonTypeButton, v26);
}