//
// GJOptionsLayer::addToggleInternal from 0x8dac60 to 0x8db1dc (1404 bytes)
//
// 3 xrefs:
// > GJOptionsLayer::addGVToggle @ 0x8db244
// > GJOptionsLayer::addToggle @ 0x8dbca0
// > ??> @ 0xa1b50
//
// 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 GJOptionsLayer::addToggleInternal(GJOptionsLayer *a1, const char *a2, int a3, bool a4, const char *a5)
{
int m_toggleCount; // w0
int v8; // w3
int v9; // w0
float v12; // s0
int v13; // w20
int m_maxPage; // w2
cocos2d::CCLayer *v15; // x24
cocos2d::CCMenu *m_buttonMenu; // x28
float m_maxLabelScale; // s9
float m_maxLabelWidth; // s8
CCMenuItemToggler *ToggleButton; // x25
void *v20; // x0
std::_Hashtable, std::allocator>, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits>::size_type M_bucket_count; // x6
std::_Hashtable, std::allocator>, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits>::__bucket_type v22; // x7
std::__detail::_Hash_node_base *M_nxt; // x4
int v24; // w0
char *v25; // x0
cocos2d::CCArray *v26; // x20
cocos2d::CCDictionary *m_values; // x24
const std::string *v28; // x1
cocos2d::CCObject *v29; // x26
char *v30; // x0
char *v31; // x0
void *v32; // x26
cocos2d::CCSprite *v33; // x24
CCMenuItemSpriteExtra *v34; // x24
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x19
__int64 v36; // x21
unsigned int *v37; // x1
int v38; // w2
__int64 v39; // x0
unsigned int *v40; // x1
int v41; // w2
unsigned int *v42; // x24
int v43; // w0
unsigned __int64 v44; // [xsp+A8h] [xbp+78h]
cocos2d::CCPoint v46; // [xsp+D8h] [xbp+A8h] BYREF
cocos2d::CCPoint v47; // [xsp+E0h] [xbp+B0h] BYREF
cocos2d::CCPoint v48; // [xsp+E8h] [xbp+B8h] BYREF
char *v49; // [xsp+F0h] [xbp+C0h] BYREF
cocos2d::SEL_MenuHandler v50; // 0:x2.16
m_toggleCount = a1->m_toggleCount;
v8 = m_toggleCount + 1;
v9 = m_toggleCount / a1->m_togglesPerPage;
a1->m_toggleCount = v8;
v12 = floorf((float)v9);
if ( v12 <= 0.0 )
v13 = 0;
else
v13 = (int)v12;
m_maxPage = a1->m_maxPage;
if ( v13 >= m_maxPage )
m_maxPage = v13;
a1->m_maxPage = m_maxPage;
GJOptionsLayer::nextPosition(a1, v13);
v15 = GJOptionsLayer::layerForPage(a1, v13);
sub_D153B8((int)&v48, (char *)a2);
m_buttonMenu = a1->m_buttonMenu;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v49, &v46);
m_maxLabelScale = a1->m_maxLabelScale;
m_maxLabelWidth = a1->m_maxLabelWidth;
cocos2d::CCPoint::CCPoint(&v47, 8.0, 0.0);
ToggleButton = GameToolbox::createToggleButton(
0.8,
m_maxLabelScale,
m_maxLabelWidth,
(__int64)&v48,
(void (__cdecl *)(cocos2d::CCObject *))GJOptionsLayer::onToggle,
0,
a4,
m_buttonMenu,
(const cocos2d::CCPoint *)&v49,
a1,
v15,
(float *)&v47,
(__int64)"bigFont.fnt",
0,
0,
nullptr);
v20 = (void *)(*(_QWORD *)&v48 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v48 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v37 = (unsigned int *)(*(_QWORD *)&v48 - 8LL);
do
v38 = __ldaxr(v37);
while ( __stlxr(v38 - 1, v37) );
}
else
{
v38 = *(_DWORD *)(*(_QWORD *)&v48 - 8LL);
*(_DWORD *)(*(_QWORD *)&v48 - 8LL) = v38 - 1;
}
if ( v38 <= 0 )
operator delete(v20);
}
ToggleButton->setTag(ToggleButton, a3);
CCMenuItemToggler::setSizeMult(ToggleButton, 1.0);
M_bucket_count = a1->m_toggleButtons._M_h._M_bucket_count;
v22 = a1->m_toggleButtons._M_h._M_buckets[a3 % M_bucket_count];
if ( !v22 )
goto LABEL_25;
M_nxt = v22->_M_nxt;
if ( a3 != LODWORD(v22->_M_nxt[1]._M_nxt) )
{
while ( M_nxt->_M_nxt )
{
v24 = (int)M_nxt->_M_nxt[1]._M_nxt;
v22 = M_nxt;
if ( a3 % M_bucket_count != v24 % M_bucket_count )
break;
M_nxt = M_nxt->_M_nxt;
if ( a3 == v24 )
goto LABEL_11;
}
goto LABEL_25;
}
LABEL_11:
if ( !v22->_M_nxt )
{
LABEL_25:
v44 = a3 % M_bucket_count;
v39 = operator new(0x18u);
*(_QWORD *)v39 = 0;
*(_DWORD *)(v39 + 8) = a3;
*(_QWORD *)(v39 + 16) = 0;
v25 = std::_Hashtable,std::allocator>,std::__detail::_Select1st,std::equal_to,std::hash,std::__detail::_Mod_range_hashing,std::__detail::_Default_ranged_hash,std::__detail::_Prime_rehash_policy,std::__detail::_Hashtable_traits>::_M_insert_unique_node(
(char **)&a1->m_toggleButtons,
v44,
a3,
(char *)v39)
+ 16;
goto LABEL_13;
}
v25 = (char *)&v22->_M_nxt[2];
LABEL_13:
*(_QWORD *)v25 = ToggleButton;
GJOptionsLayer::incrementCountForPage(a1, v13);
v26 = GJOptionsLayer::objectsForPage(a1, v13);
cocos2d::CCArray::addObject(v26, ToggleButton);
ToggleButton->setVisible(ToggleButton, 0);
v15->setVisible(v15, 0);
if ( a5 && *a5 )
{
m_values = a1->m_values;
sub_D153B8((int)&v48, (char *)a5);
v29 = (cocos2d::CCObject *)cocos2d::CCString::create((cocos2d::CCString *)&v48, v28);
v30 = (char *)GJOptionsLayer::infoKey(a1, a3);
sub_D153B8((int)&v49, v30);
cocos2d::CCDictionary::setObject((int)m_values, v29);
v31 = v49 - 24;
if ( v49 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v40 = (unsigned int *)(v49 - 8);
do
v41 = __ldaxr(v40);
while ( __stlxr(v41 - 1, v40) );
}
else
{
v41 = *((_DWORD *)v49 - 2);
*((_DWORD *)v49 - 2) = v41 - 1;
}
if ( v41 <= 0 )
operator delete(v31);
}
v32 = (void *)(*(_QWORD *)&v48 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v48 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v42 = (unsigned int *)(*(_QWORD *)&v48 - 8LL);
do
v43 = __ldaxr(v42);
while ( __stlxr(v43 - 1, v42) );
}
else
{
v43 = *(_DWORD *)(*(_QWORD *)&v48 - 8LL);
*(_DWORD *)(*(_QWORD *)&v48 - 8LL) = v43 - 1;
}
if ( v43 <= 0 )
operator delete(v32);
}
v33 = cocos2d::CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png");
v33->setScale(v33, 0.5);
v50.ptr = (void (__cdecl *)(cocos2d::CCObject *))a1;
v50.adj = (size_t)GJOptionsLayer::onInfo;
v34 = CCMenuItemSpriteExtra::create(v33, nullptr, v50);
CCMenuItemSpriteExtra::setSizeMult(v34, 2.0);
v34->setTag(v34, a3);
a1->m_buttonMenu->addChild(a1->m_buttonMenu, v34);
setPosition = v34->setPosition;
v36 = (__int64)ToggleButton->getPosition(ToggleButton);
cocos2d::CCPoint::CCPoint(&v48, -18.0, 16.0);
cocos2d::CCPoint::operator+(&v49, v36, &v48);
setPosition(v34, (const cocos2d::CCPoint *)&v49);
cocos2d::CCArray::addObject(v26, v34);
v34->setVisible(v34, 0);
}
}