//
// ParentalOptionsLayer::addToggle from 0x14037b9e0 to 0x14037be41 (1121 bytes)
//
// 4 xrefs:
// > ParentalOptionsLayer::init @ 0x14037b77f
// > ParentalOptionsLayer::init @ 0x14037b795
// > ParentalOptionsLayer::init @ 0x14037b7ab
// > ??> @ 0x1406d5cfc
//
// 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=5
void ParentalOptionsLayer::addToggle(ParentalOptionsLayer *a1, const char *a2, const char *a3, const char *a4)
{
int m_toggleCount; // ecx
int v8; // r15d
int m_maxPage; // eax
int v10; // eax
__int64 v11; // r12
GameManager *v12; // rcx
size_t v13; // rdi
size_t v14; // r8
struct cocos2d::CCObject *v15; // rax
__int64 v16; // rcx
void *v17; // rcx
cocos2d::CCDirector *v18; // rax
double v19; // xmm0_8
int v20; // r13d
float v21; // xmm0_4
cocos2d::CCLayer *v22; // r12
size_t v23; // r8
float *v24; // rax
float *v25; // rbx
struct cocos2d::CCPoint v26; // rax
CCMenuItemToggler *ToggleButton; // rbx
int v28; // r14d
cocos2d::CCString *v29; // rax
const char *CString; // rax
struct cocos2d::CCString *v31; // rax
void *v32; // rcx
cocos2d::CCArray *v33; // rax
bool GameVariable; // [rsp+80h] [rbp-80h]
cocos2d::CCPoint v35; // [rsp+88h] [rbp-78h] BYREF
int v36; // [rsp+90h] [rbp-70h]
cocos2d::CCPoint v37; // [rsp+98h] [rbp-68h] BYREF
__int128 *v38; // [rsp+A8h] [rbp-58h]
__int128 v39; // [rsp+B0h] [rbp-50h] BYREF
__int64 v40; // [rsp+C0h] [rbp-40h]
__int64 v41; // [rsp+C8h] [rbp-38h]
void *Block[2]; // [rsp+D0h] [rbp-30h] BYREF
__int64 v43; // [rsp+E0h] [rbp-20h]
unsigned __int64 v44; // [rsp+E8h] [rbp-18h]
m_toggleCount = a1->m_toggleCount;
a1->m_toggleCount = m_toggleCount + 1;
v8 = (int)fmaxf(0.0, floorf((float)(m_toggleCount / 10)));
m_maxPage = a1->m_maxPage;
if ( m_maxPage <= v8 )
m_maxPage = v8;
a1->m_maxPage = m_maxPage;
v10 = atoi(a3);
v11 = v10;
v36 = v10;
v12 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v38 = (__int128 *)operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v38);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v12 = (GameManager *)qword_1406C2ED8;
}
GameVariable = GameManager::getGameVariable(v12, a3);
*(_OWORD *)Block = 0;
v43 = 0;
v44 = 0;
v13 = -1;
v14 = -1;
do
++v14;
while ( a3[v14] );
sub_14003A930(Block, a3, v14);
v15 = (struct cocos2d::CCObject *)cocos2d::CCString::create(Block);
cocos2d::CCDictionary::setObject(a1->m_variables, v15, v11);
if ( v44 > 0xF )
{
v17 = Block[0];
if ( v44 + 1 >= 0x1000 )
{
v17 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v17);
}
v18 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v16);
cocos2d::CCDirector::getWinSize(v18);
v19 = cocos2d::CCPoint::CCPoint(0.0, (float)(v35.x * 0.5) - 135.0);
cocos2d::CCPoint::CCPoint(*(float *)&v19, (float)(v35.x * 0.5) + 35.0);
v20 = KeybindingsLayer::countForPage((__int64)a1, v8);
cocos2d::CCPoint::CCPoint(&v37);
if ( v20 + 1 > 2 )
{
v21 = floorf((float)v20 * 0.5);
v37.y = v37.y - (float)(48 * (int)v21);
}
v22 = ParentalOptionsLayer::layerForPage(a1, v8);
v38 = &v39;
v39 = 0;
v40 = 0;
v41 = 0;
v23 = -1;
do
++v23;
while ( a2[v23] );
sub_14003A930(&v39, a2, v23);
cocos2d::CCPoint::CCPoint(0.0, 8.0);
v25 = v24;
cocos2d::CCPoint::CCPoint(&v35);
ToggleButton = GameToolbox::createToggleButton(
(const char *)&v39,
(cocos2d::SEL_MenuHandler *)ParentalOptionsLayer::onToggle,
GameVariable,
a1->m_buttonMenu,
v26,
a1,
v22,
0.80000001,
0.5,
110.0,
v25,
(const char *)&qword_14052A4D8,
0,
0,
nullptr);
ToggleButton->setTag(ToggleButton, v36);
*(_DWORD *)(*(_QWORD *)&ToggleButton->m_nScriptTapHandler + 372LL) = 1065353216;
HIDWORD(ToggleButton->m_offButton->m_pfnSelector.adj) = 1065353216;
CCMenuItemToggler::toggle(ToggleButton, (bool)ToggleButton->m_onButton);
v28 = KeybindingsLayer::countForPage((__int64)a1, v8);
v29 = cocos2d::CCString::createWithFormat("page_%i", v8);
CString = cocos2d::CCString::getCString(v29);
*(_OWORD *)Block = 0;
v43 = 0;
v44 = 0;
do
++v13;
while ( CString[v13] );
sub_14003A930(Block, CString, v13);
v31 = cocos2d::CCString::createWithFormat("%i", v28 + 1);
cocos2d::CCDictionary::setObject(a1->m_values, v31, Block);
if ( v44 > 0xF )
{
v32 = Block[0];
if ( v44 + 1 >= 0x1000 )
{
v32 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v32 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v32);
}
v33 = ParentalOptionsLayer::objectsForPage(a1, v8);
cocos2d::CCArray::addObject(v33, ToggleButton);
ToggleButton->setVisible(ToggleButton, 0);
v22->setVisible(v22, 0);
}