//
// LevelSearchLayer::toggleDifficulty from 0x140311f70 to 0x1403122c1 (849 bytes)
//
// 2 xrefs:
// > LevelSearchLayer::init @ 0x14030d5bb
// > ??> @ 0x1406d4850
//
// 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
//
// Hidden C++ exception states: #wind=2
void LevelSearchLayer::toggleDifficulty(LevelSearchLayer *a1, cocos2d::CCObject *a2)
{
int v3; // r14d
bool v4; // r15
int i; // ebx
bool v6; // r15
cocos2d::CCString *v7; // rax
const char *CString; // rax
size_t v9; // rsi
size_t v10; // r8
struct cocos2d::CCString *v11; // rax
void *v12; // rcx
int *p_m_unknown2; // rcx
void (__fastcall *v14)(int *, __int16 *); // r8
__int16 *v15; // rdx
int j; // ebx
int k; // ebx
int m; // ebx
GameLevelManager *v19; // rcx
cocos2d::CCString *v20; // rax
const char *v21; // rax
cocos2d::CCString *v22; // rax
bool v23; // bl
void *v24; // rcx
__int16 v25; // [rsp+20h] [rbp-40h] BYREF
char v26; // [rsp+22h] [rbp-3Eh]
_WORD v27[2]; // [rsp+24h] [rbp-3Ch] BYREF
void *v28; // [rsp+28h] [rbp-38h]
void *Block[2]; // [rsp+30h] [rbp-30h] BYREF
__int64 v30; // [rsp+40h] [rbp-20h]
unsigned __int64 v31; // [rsp+48h] [rbp-18h]
v3 = a2->getTag(a2);
v4 = LevelSearchLayer::checkDiff(a1, v3);
if ( a1->m_type == 1 )
{
for ( i = 0; i <= 7; ++i )
{
if ( i != v3 )
LevelSearchLayer::toggleDifficultyNum(a1, i, 0);
}
}
v6 = !v4;
v7 = cocos2d::CCString::createWithFormat("D%i", v3);
CString = cocos2d::CCString::getCString(v7);
*(_OWORD *)Block = 0;
v30 = 0;
v31 = 0;
v9 = -1;
v10 = -1;
do
++v10;
while ( CString[v10] );
sub_14003A930(Block, CString, v10);
v11 = cocos2d::CCString::createWithFormat("%i", v6);
cocos2d::CCDictionary::setObject(a1->m_difficultyDict, v11, Block);
if ( v31 > 0xF )
{
v12 = Block[0];
if ( v31 + 1 >= 0x1000 )
{
v12 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v12 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v12);
}
p_m_unknown2 = &cocos2d::CCArray::objectAtIndex(a1->m_difficultySprites, v3)[5].m_unknown2;
v14 = **(void (__fastcall ***)(int *, __int16 *))p_m_unknown2;
if ( v6 )
{
v25 = -1;
v26 = -1;
v15 = &v25;
}
else
{
v25 = 32125;
memset(v27, 125, 3);
v15 = v27;
}
v14(p_m_unknown2, v15);
if ( !v3 )
{
if ( v6 )
{
for ( j = 1; j <= 7; ++j )
LevelSearchLayer::toggleDifficultyNum(a1, j, 0);
goto LABEL_33;
}
goto LABEL_31;
}
if ( v3 == 6 )
{
if ( v6 )
{
for ( k = 0; k <= 5; ++k )
LevelSearchLayer::toggleDifficultyNum(a1, k, 0);
goto LABEL_32;
}
LABEL_31:
LevelSearchLayer::toggleDifficultyNum(a1, 0, 0);
LevelSearchLayer::toggleDifficultyNum(a1, 6, 0);
LABEL_32:
LevelSearchLayer::toggleDifficultyNum(a1, 7, 0);
goto LABEL_33;
}
if ( v3 != 7 || !v6 )
goto LABEL_31;
for ( m = 0; m <= 6; ++m )
LevelSearchLayer::toggleDifficultyNum(a1, m, 0);
LABEL_33:
v19 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v28 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v28);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v19 = (GameLevelManager *)qword_1406C2EC0;
}
GameLevelManager::setDiffVal(v19, v3, v6);
v20 = cocos2d::CCString::createWithFormat("D%i", 6);
v21 = cocos2d::CCString::getCString(v20);
*(_OWORD *)Block = 0;
v30 = 0;
v31 = 0;
do
++v9;
while ( v21[v9] );
sub_14003A930(Block, v21, v9);
v22 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(a1->m_difficultyDict, Block);
v23 = cocos2d::CCString::boolValue(v22);
if ( v31 > 0xF )
{
v24 = Block[0];
if ( v31 + 1 >= 0x1000 )
{
v24 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v24 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v24);
}
a1->m_demonTypeButton->setEnabled(a1->m_demonTypeButton, v23);
a1->m_demonTypeButton->setVisible(a1->m_demonTypeButton, v23);
}