//
// ParentalOptionsLayer::addToggle from 0x7d1adc to 0x7d205c (1408 bytes)
//
// 4 xrefs:
// > ParentalOptionsLayer::init @ 0x7d2844
// > ParentalOptionsLayer::init @ 0x7d2860
// > ParentalOptionsLayer::init @ 0x7d287c
// > ??> @ 0xc74b8
//
// 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 ParentalOptionsLayer::addToggle(ParentalOptionsLayer *a1, const char *a2, const char *a3, const char *a4)
{
int m_toggleCount; // w0
float v9; // s0
int v10; // w19
int m_maxPage; // w1
unsigned int v12; // w24
GameManager *v13; // x0
char *v14; // x1
cocos2d::CCDictionary *m_variables; // x22
const std::string *v16; // x1
cocos2d::CCObject *v17; // x0
void *v18; // x0
cocos2d::CCLayer *v19; // x25
CCMenuItemToggler *v20; // x26
char *v21; // x0
cocos2d::CCArray *v22; // x19
cocos2d::CCDictionary *m_values; // x25
const std::string *v24; // x1
cocos2d::CCObject *v25; // x28
char *v26; // x0
void *v27; // x0
char *v28; // x0
cocos2d::CCSprite *v29; // x23
CCMenuItemSpriteExtra *v30; // x23
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x20
__int64 v32; // x24
unsigned int *v33; // x1
int v34; // w2
unsigned int *v35; // x1
int v36; // w2
unsigned int *v37; // x1
int v38; // w2
unsigned int *v39; // x1
int v40; // w2
bool GameVariable; // [xsp+9Fh] [xbp+6Fh]
cocos2d::CCMenu *m_buttonMenu; // [xsp+A0h] [xbp+70h]
cocos2d::CCPoint v43; // [xsp+C8h] [xbp+98h] BYREF
cocos2d::CCPoint v44; // [xsp+D0h] [xbp+A0h] BYREF
char *v45; // [xsp+D8h] [xbp+A8h] BYREF
cocos2d::CCPoint v46; // [xsp+E0h] [xbp+B0h] BYREF
cocos2d::SEL_MenuHandler v47; // 0:x2.16
m_toggleCount = a1->m_toggleCount;
a1->m_toggleCount = m_toggleCount + 1;
v9 = floorf((float)(m_toggleCount / 10));
if ( v9 <= 0.0 )
v10 = 0;
else
v10 = (int)v9;
m_maxPage = a1->m_maxPage;
if ( v10 >= m_maxPage )
m_maxPage = v10;
a1->m_maxPage = m_maxPage;
v12 = atoi(a3);
v13 = GameManager::sharedState();
GameVariable = GameManager::getGameVariable(v13, a3);
v14 = (char *)a3;
m_variables = a1->m_variables;
sub_D153B8((int)&v46, v14);
v17 = (cocos2d::CCObject *)cocos2d::CCString::create((cocos2d::CCString *)&v46, v16);
cocos2d::CCDictionary::setObject(m_variables, v17, (int)v12);
v18 = (void *)(*(_QWORD *)&v46 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v46 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v35 = (unsigned int *)(*(_QWORD *)&v46 - 8LL);
do
v36 = __ldaxr(v35);
while ( __stlxr(v36 - 1, v35) );
}
else
{
v36 = *(_DWORD *)(*(_QWORD *)&v46 - 8LL);
*(_DWORD *)(*(_QWORD *)&v46 - 8LL) = v36 - 1;
}
if ( v36 <= 0 )
operator delete(v18);
}
ParentalOptionsLayer::nextPosition(a1, v10);
v19 = ParentalOptionsLayer::layerForPage(a1, v10);
sub_D153B8((int)&v45, (char *)a2);
m_buttonMenu = a1->m_buttonMenu;
cocos2d::CCPoint::CCPoint(&v46, &v43);
cocos2d::CCPoint::CCPoint(&v44, 8.0, 0.0);
v20 = GameToolbox::createToggleButton(
0.8,
0.5,
110.0,
(__int64)&v45,
(void (__cdecl *)(cocos2d::CCObject *))ParentalOptionsLayer::onToggle,
0,
GameVariable,
m_buttonMenu,
&v46,
a1,
v19,
(float *)&v44,
(__int64)"bigFont.fnt",
0,
0,
nullptr);
v21 = v45 - 24;
if ( v45 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v33 = (unsigned int *)(v45 - 8);
do
v34 = __ldaxr(v33);
while ( __stlxr(v34 - 1, v33) );
}
else
{
v34 = *((_DWORD *)v45 - 2);
*((_DWORD *)v45 - 2) = v34 - 1;
}
if ( v34 <= 0 )
operator delete(v21);
}
v20->setTag(v20, v12);
CCMenuItemToggler::setSizeMult(v20, 1.0);
ParentalOptionsLayer::incrementCountForPage(a1, v10);
v22 = ParentalOptionsLayer::objectsForPage(a1, v10);
cocos2d::CCArray::addObject(v22, v20);
v20->setVisible(v20, 0);
v19->setVisible(v19, 0);
if ( a4 )
{
m_values = a1->m_values;
sub_D153B8((int)&v45, (char *)a4);
v25 = (cocos2d::CCObject *)cocos2d::CCString::create((cocos2d::CCString *)&v45, v24);
v26 = (char *)ParentalOptionsLayer::infoKey(a1, v12);
sub_D153B8((int)&v46, v26);
cocos2d::CCDictionary::setObject((int)m_values, v25);
v27 = (void *)(*(_QWORD *)&v46 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v46 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v39 = (unsigned int *)(*(_QWORD *)&v46 - 8LL);
do
v40 = __ldaxr(v39);
while ( __stlxr(v40 - 1, v39) );
}
else
{
v40 = *(_DWORD *)(*(_QWORD *)&v46 - 8LL);
*(_DWORD *)(*(_QWORD *)&v46 - 8LL) = v40 - 1;
}
if ( v40 <= 0 )
operator delete(v27);
}
v28 = v45 - 24;
if ( v45 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v37 = (unsigned int *)(v45 - 8);
do
v38 = __ldaxr(v37);
while ( __stlxr(v38 - 1, v37) );
}
else
{
v38 = *((_DWORD *)v45 - 2);
*((_DWORD *)v45 - 2) = v38 - 1;
}
if ( v38 <= 0 )
operator delete(v28);
}
v29 = cocos2d::CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png");
v29->setScale(v29, 0.5);
v47.ptr = (void (__cdecl *)(cocos2d::CCObject *))a1;
v47.adj = (size_t)ParentalOptionsLayer::onInfo;
v30 = CCMenuItemSpriteExtra::create(v29, nullptr, v47);
CCMenuItemSpriteExtra::setSizeMult(v30, 2.0);
v30->setTag(v30, v12);
a1->m_buttonMenu->addChild(a1->m_buttonMenu, v30);
setPosition = v30->setPosition;
v32 = (__int64)v20->getPosition(v20);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v45, -18.0, 16.0);
cocos2d::CCPoint::operator+(&v46, v32, &v45);
setPosition(v30, &v46);
cocos2d::CCArray::addObject(v22, v30);
v30->setVisible(v30, 0);
}
}