//
// GJOptionsLayer::addToggleInternal from 0x4b4308 to 0x4b45bc (692 bytes)
//
// 2 xrefs:
// > GJOptionsLayer::addGVToggle @ 0x4b460e
// > GJOptionsLayer::addToggle @ 0x4b4da0
//
// 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 v5; // r8
int m_toggleCount; // r0
int m_togglesPerPage; // r1
float v11; // r0
int m_maxPage; // r3
int v13; // s15
cocos2d::CCLayer *v14; // r9
cocos2d::CCMenu *m_buttonMenu; // r7
float m_maxLabelScale; // s16
float m_maxLabelWidth; // r11
CCMenuItemToggler *v18; // r5
unsigned int v19; // r7
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 v20; // r11
_DWORD **v21; // r0
_DWORD *inserted; // r0
cocos2d::CCArray *v23; // r10
const std::string *v24; // r1
cocos2d::CCObject *v25; // r11
char *v26; // r0
cocos2d::CCSprite *v27; // r9
CCMenuItemSpriteExtra *v28; // r9
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // r4
int v30; // r7
_DWORD *v31; // r0
cocos2d::CCDictionary *m_values; // [sp+38h] [bp-14h]
int v33; // [sp+44h] [bp-8h] BYREF
cocos2d::CCPoint v34; // [sp+4Ch] [bp+0h] BYREF
cocos2d::CCPoint v35; // [sp+54h] [bp+8h] BYREF
cocos2d::CCPoint v36; // [sp+5Ch] [bp+10h] BYREF
void (*v37)(GJOptionsLayer *, cocos2d::CCObject *); // [sp+64h] [bp+18h]
unsigned int v38; // [sp+68h] [bp+1Ch]
cocos2d::CCPoint v39; // [sp+6Ch] [bp+20h] BYREF
m_toggleCount = a1->m_toggleCount;
m_togglesPerPage = a1->m_togglesPerPage;
v33 = a3;
a1->m_toggleCount = m_toggleCount + 1;
v11 = floorf((float)(m_toggleCount / m_togglesPerPage));
m_maxPage = a1->m_maxPage;
v13 = LODWORD(v11);
if ( v11 <= 0.0 )
v5 = 0;
else
v13 = (int)v11;
if ( v11 > 0.0 )
v5 = v13;
if ( m_maxPage < v5 )
a1->m_maxPage = v5;
else
a1->m_maxPage = m_maxPage;
GJOptionsLayer::nextPosition(&v34, a1, v5);
v14 = GJOptionsLayer::layerForPage(a1, v5);
sub_776584((int)&v35, (char *)a2);
m_buttonMenu = a1->m_buttonMenu;
v37 = GJOptionsLayer::onToggle;
v38 = 0;
cocos2d::CCPoint::CCPoint(&v39, &v34);
m_maxLabelScale = a1->m_maxLabelScale;
m_maxLabelWidth = a1->m_maxLabelWidth;
cocos2d::CCPoint::CCPoint(&v36, 8.0, 0.0);
v18 = GameToolbox::createToggleButton(
(int)&v35,
(unsigned int)v37,
v38,
a4,
m_buttonMenu,
&v39,
a1,
v14,
0.8,
m_maxLabelScale,
m_maxLabelWidth,
(int)&v36,
(int)"bigFont.fnt",
0,
0,
nullptr);
sub_774008(&v35);
v19 = v33;
v18->setTag(v18, v33);
CCMenuItemToggler::setSizeMult(v18, 1.0);
v20 = v19 % a1->m_toggleButtons._M_h._M_bucket_count;
v21 = sub_4A9C94(&a1->m_toggleButtons._M_h._M_buckets, v20, &v33);
if ( !v21 || (inserted = *v21) == nullptr )
{
v31 = (_DWORD *)operator new(0xCu);
*v31 = 0;
v31[1] = v19;
v31[2] = 0;
inserted = 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(
(int)&a1->m_toggleButtons,
v20,
v19,
v31);
}
inserted[2] = v18;
GJOptionsLayer::incrementCountForPage(a1, v5);
v23 = GJOptionsLayer::objectsForPage(a1, v5);
cocos2d::CCArray::addObject(v23, v18);
v18->setVisible(v18, 0);
v14->setVisible(v14, 0);
if ( a5 )
{
if ( *a5 )
{
m_values = a1->m_values;
sub_776584((int)&v36, (char *)a5);
v25 = (cocos2d::CCObject *)cocos2d::CCString::create((cocos2d::CCString *)&v36, v24);
v26 = (char *)GJOptionsLayer::infoKey(a1, v19);
sub_776584((int)&v39, v26);
cocos2d::CCDictionary::setObject((int)m_values, v25);
sub_774008(&v39);
sub_774008(&v36);
v27 = cocos2d::CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png");
((void (__fastcall *)(cocos2d::CCSprite *, int))v27->setScale)(v27, 1056964608);
LODWORD(v39.x) = GJOptionsLayer::onInfo;
v39.y = 0.0;
v28 = CCMenuItemSpriteExtra::create(
v27,
nullptr,
(cocos2d::SEL_MenuHandler)__PAIR64__(GJOptionsLayer::onInfo, (unsigned int)a1));
CCMenuItemSpriteExtra::setSizeMult(v28, 2.0);
v28->setTag(v28, v19);
a1->m_buttonMenu->addChild(a1->m_buttonMenu, v28);
setPosition = v28->setPosition;
v30 = (int)v18->getPosition(v18);
cocos2d::CCPoint::CCPoint(&v35, -18.0, 16.0);
cocos2d::CCPoint::operator+(&v36, v30, &v35);
setPosition(v28, &v36);
cocos2d::CCArray::addObject(v23, v28);
v28->setVisible(v28, 0);
}
}
}