//
// LevelSearchLayer::toggleDifficulty from 0x14043abe0 to 0x14043af55 (885 bytes)
//
// 2 xrefs:
// > LevelSearchLayer::init @ 0x140435942
// > ??> @ 0x140926f0c
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:32:19 +0000
//
// Hidden C++ exception states: #wind=2
__int64 __fastcall LevelSearchLayer::toggleDifficulty(__int64 a1, __int64 a2)
{
unsigned int v3; // r14d
bool v4; // si
int i; // ebx
unsigned int v6; // r15d
cocos2d::CCString *v7; // rax
const char *CString; // rax
size_t v9; // rsi
size_t v10; // r8
struct cocos2d::CCString *v11; // rax
void *v12; // rcx
char *v13; // rcx
void (__fastcall *v14)(char *, __int16 *); // r8
__int16 *v15; // rdx
int j; // ebx
int k; // ebx
int m; // ebx
__int64 v19; // rcx
cocos2d::CCString *v20; // rax
const char *v21; // rax
cocos2d::CCString *v22; // rax
bool v23; // bl
void *v24; // r8
__int16 v26; // [rsp+30h] [rbp-40h] BYREF
char v27; // [rsp+32h] [rbp-3Eh]
_WORD v28[2]; // [rsp+34h] [rbp-3Ch] BYREF
void *v29; // [rsp+38h] [rbp-38h]
void *Block[2]; // [rsp+40h] [rbp-30h] BYREF
__int64 v31; // [rsp+50h] [rbp-20h]
unsigned __int64 v32; // [rsp+58h] [rbp-18h]
v3 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)a2 + 56LL))(a2);
v4 = LevelSearchLayer::checkDiff(a1, v3);
if ( *(_DWORD *)(a1 + 432) == 1 )
{
for ( i = 0; i <= 7; ++i )
{
if ( i != v3 )
LevelSearchLayer::toggleDifficultyNum(a1, (unsigned int)i, 0);
}
}
v6 = !v4;
v7 = cocos2d::CCString::createWithFormat("D%i", v3);
CString = cocos2d::CCString::getCString(v7);
*(_OWORD *)Block = 0;
v31 = 0;
v32 = 0;
v9 = -1;
v10 = -1;
do
++v10;
while ( CString[v10] );
sub_14003D230(Block, CString, v10);
v11 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, v6);
cocos2d::CCDictionary::setObject(*(_QWORD *)(a1 + 480), v11, Block);
if ( v32 > 0xF )
{
v12 = Block[0];
if ( v32 + 1 >= 0x1000 )
{
v12 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v12 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v12);
}
v13 = (char *)cocos2d::CCArray::objectAtIndex(*(cocos2d::CCArray **)(a1 + 464), v3) + 320;
v14 = **(void (__fastcall ***)(char *, __int16 *))v13;
if ( (_BYTE)v6 )
{
v26 = -1;
v27 = -1;
v15 = &v26;
}
else
{
v26 = 32125;
memset(v28, 125, 3);
v15 = v28;
}
v14(v13, v15);
if ( !v3 )
{
if ( (_BYTE)v6 )
{
for ( j = 1; j <= 7; ++j )
LevelSearchLayer::toggleDifficultyNum(a1, (unsigned int)j, 0);
goto LABEL_33;
}
goto LABEL_31;
}
if ( v3 == 6 )
{
if ( (_BYTE)v6 )
{
for ( k = 0; k <= 5; ++k )
LevelSearchLayer::toggleDifficultyNum(a1, (unsigned int)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 || !(_BYTE)v6 )
goto LABEL_31;
for ( m = 0; m <= 6; ++m )
LevelSearchLayer::toggleDifficultyNum(a1, (unsigned int)m, 0);
LABEL_33:
v19 = *(_QWORD *)&qword_14090BFB0;
if ( !*(_QWORD *)&qword_14090BFB0 )
{
v29 = operator new(0x690u);
*(_QWORD *)&qword_14090BFB0 = GameLevelManager::GameLevelManager((__int64)v29);
(*(void (__fastcall **)(_QWORD))(**(_QWORD **)&qword_14090BFB0 + 72LL))(*(_QWORD *)&qword_14090BFB0);
v19 = *(_QWORD *)&qword_14090BFB0;
}
GameLevelManager::setDiffVal(v19, v3, v6);
v20 = cocos2d::CCString::createWithFormat("D%i", 6);
v21 = cocos2d::CCString::getCString(v20);
*(_OWORD *)Block = 0;
v31 = 0;
v32 = 0;
do
++v9;
while ( v21[v9] );
sub_14003D230(Block, v21, v9);
v22 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(*(_QWORD *)(a1 + 480), Block);
v23 = cocos2d::CCString::boolValue(v22);
if ( v32 > 0xF )
{
v24 = Block[0];
if ( v32 + 1 >= 0x1000 )
{
v24 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v24 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v24);
}
(*(void (__fastcall **)(_QWORD, bool))(**(_QWORD **)(a1 + 496) + 936LL))(*(_QWORD *)(a1 + 496), v23);
return (*(__int64 (__fastcall **)(_QWORD, bool))(**(_QWORD **)(a1 + 496) + 336LL))(*(_QWORD *)(a1 + 496), v23);
}