//
// SetupRandAdvTriggerPopup::updateGroupIDButtons from 0x9af160 to 0x9af9e0 (2176 bytes)
//
// 7 xrefs:
// > SetupRandAdvTriggerPopup::init @ 0x9b021c
// > SetupRandAdvTriggerPopup::addChance @ 0x9b06a0
// > SetupRandAdvTriggerPopup::addChance @ 0x9b06f0
// > SetupRandAdvTriggerPopup::removeGroupID @ 0x9b0734
// > SetupRandAdvTriggerPopup::removeGroupID @ 0x9b0780
// > SetupRandAdvTriggerPopup::onAddChance @ 0x9b086c
// > ??> @ 0x42d38
//
// 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 SetupRandAdvTriggerPopup::updateGroupIDButtons(SetupRandAdvTriggerPopup *a1)
{
unsigned int i; // w19
unsigned int v3; // w1
__int64 v4; // x0
bool v5; // cf
cocos2d::CCArray *m_groupButtons; // x0
RandTriggerGameObject *m_gameObject; // x23
cocos2d::CCPoint m_start; // x19
ChanceObject *m_finish; // x22
char *v10; // x1
char *v11; // x0
int v12; // w28
float v13; // s8
float v14; // s9
float v15; // s10
cocos2d::CCDirector *v16; // x0
cocos2d::CCMenu *m_buttonMenu; // x19
double v18; // d0
char *v19; // x20
char *v20; // x22
__int64 v21; // x19
char *v22; // x27
unsigned __int64 v23; // x19
int *v24; // x22
const char *v25; // x27
int v26; // w2
_BOOL4 v27; // w26
cocos2d::CCString *v28; // x0
size_t v29; // x0
const char *v30; // x6
__int64 v31; // x0
cocos2d::CCNode *v32; // x27
__int64 v33; // x0
void (__fastcall *v34)(__int64, __int64 **); // x2
CCMenuItemSpriteExtra *v35; // x26
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x27
cocos2d::CCPoint *p_m_textOffset; // x0
unsigned int v38; // w20
char *v39; // x19
const char *v40; // x1
unsigned int *p_m_caption; // x1
int m_data; // w2
unsigned __int64 v43; // x0
double v44; // d0
size_t v45; // x19
__int64 *v46; // x20
int v47; // w22
RandTriggerGameObject *v48; // x19
int v49; // w0
ChanceObject *v50; // x20
ChanceObject *v51; // x23
int m_groupID; // w19
unsigned __int64 v53; // x6
__int64 **v54; // x0
__int64 *v55; // x1
int v56; // w0
__int64 v57; // x5
int m_chance; // w27
__int64 v59; // x0
int v60; // w6
_DWORD *v61; // x3
unsigned __int64 v62; // x5
cocos2d::CCPoint v63; // x0
unsigned __int64 v64; // x1
char **v65; // x7
char *v66; // x0
int v67; // w19
char *inserted; // x19
__int64 *j; // x19
char *v70; // x1
unsigned int v71; // w25
const char *CString; // [xsp+80h] [xbp+80h]
signed int v73; // [xsp+98h] [xbp+98h]
unsigned int v74; // [xsp+98h] [xbp+98h]
int TotalChance; // [xsp+9Ch] [xbp+9Ch]
float v76; // [xsp+A8h] [xbp+A8h]
float v77; // [xsp+ACh] [xbp+ACh]
char v78[8]; // [xsp+B0h] [xbp+B0h] BYREF
ButtonSprite *v79; // [xsp+B8h] [xbp+B8h] BYREF
__int64 *v80; // [xsp+C0h] [xbp+C0h] BYREF
void *p; // [xsp+C8h] [xbp+C8h] BYREF
char *v82; // [xsp+D0h] [xbp+D0h]
char *v83; // [xsp+D8h] [xbp+D8h]
__int64 *v84; // [xsp+E0h] [xbp+E0h] BYREF
unsigned __int64 v85; // [xsp+E8h] [xbp+E8h]
__int64 *v86; // [xsp+F0h] [xbp+F0h]
__int64 v87; // [xsp+F8h] [xbp+F8h]
float v88; // [xsp+100h] [xbp+100h] BYREF
__int64 v89; // [xsp+108h] [xbp+108h]
__int64 v90; // [xsp+110h] [xbp+110h] BYREF
cocos2d::SEL_MenuHandler v91; // 0:x2.16
for ( i = 0; ; ++i )
{
v5 = i >= (unsigned int)cocos2d::CCArray::count(a1->m_groupButtons);
m_groupButtons = a1->m_groupButtons;
if ( v5 )
break;
v3 = i;
v4 = cocos2d::CCArray::objectAtIndex(m_groupButtons, v3);
(*(void (__fastcall **)(__int64))(*(_QWORD *)v4 + 504LL))(v4);
}
cocos2d::CCArray::removeAllObjects(m_groupButtons);
m_gameObject = (RandTriggerGameObject *)a1->m_gameObject;
p = nullptr;
v82 = nullptr;
v83 = nullptr;
if ( m_gameObject )
{
m_start = (cocos2d::CCPoint)m_gameObject->m_chanceObjects.m_start;
m_finish = m_gameObject->m_chanceObjects.m_finish;
if ( *(ChanceObject **)&m_start != m_finish )
{
v10 = nullptr;
v11 = nullptr;
while ( 1 )
{
v84 = (__int64 *)m_start;
if ( v11 == v10 )
{
std::vector::_M_emplace_back_aux((__int64)&p, &v84);
*(_QWORD *)&m_start += 16LL;
if ( m_finish == *(ChanceObject **)&m_start )
break;
}
else
{
if ( v11 )
{
*(cocos2d::CCPoint *)v11 = m_start;
v11 = v82;
}
*(_QWORD *)&m_start += 16LL;
v82 = v11 + 8;
if ( m_finish == *(ChanceObject **)&m_start )
break;
}
v11 = v82;
v10 = v83;
}
}
TotalChance = RandTriggerGameObject::getTotalChance(m_gameObject);
v12 = 1;
LABEL_14:
v13 = 66.0;
v14 = 40.0;
v73 = (unsigned int)&byte_5;
v15 = 2.0;
goto LABEL_15;
}
v86 = nullptr;
v87 = 0;
v88 = 1.0;
v89 = 0;
v43 = sub_D146DC(&v88, 10);
v85 = v43;
if ( v43 == 1 )
{
v90 = 0;
v46 = &v90;
}
else
{
if ( v43 > 0x1FFFFFFFFFFFFFFFLL )
sub_D1383C(v44);
v45 = 8 * v43;
v46 = (__int64 *)operator new(8 * v43);
memset(v46, 0, v45);
}
v12 = 1;
v84 = v46;
v74 = 0;
v47 = 0;
TotalChance = 0;
LABEL_55:
if ( v74 < (unsigned int)cocos2d::CCArray::count(a1->m_gameObjects) )
{
v48 = (RandTriggerGameObject *)cocos2d::CCArray::objectAtIndex(a1->m_gameObjects, v74);
v49 = RandTriggerGameObject::getTotalChance(v48);
v50 = v48->m_chanceObjects.m_start;
v51 = v48->m_chanceObjects.m_finish;
TotalChance = v49;
if ( v50 == v51 )
goto LABEL_77;
while ( 1 )
{
m_groupID = v50->m_groupID;
v53 = v50->m_groupID % v85;
v54 = (__int64 **)v84[v53];
if ( !v54 )
goto LABEL_67;
v55 = *v54;
if ( !*v54 )
goto LABEL_67;
v56 = *((_DWORD *)v55 + 2);
v57 = 0;
while ( m_groupID == v56 )
{
v55 = (__int64 *)*v55;
++v57;
if ( !v55 )
goto LABEL_65;
LABEL_62:
v56 = *((_DWORD *)v55 + 2);
if ( v53 != v56 % v85 )
goto LABEL_65;
}
if ( v57 )
goto LABEL_66;
v55 = (__int64 *)*v55;
if ( v55 )
goto LABEL_62;
LABEL_65:
if ( !v57 )
goto LABEL_67;
LABEL_66:
__break(0x3E8u);
LABEL_67:
m_chance = v50->m_chance;
v59 = operator new(0x20u);
v60 = v50->m_groupID;
v61 = (_DWORD *)v59;
v62 = v85;
*(_QWORD *)v59 = 0;
*(_DWORD *)(v59 + 8) = v60;
v63 = (cocos2d::CCPoint)v84;
v61[3] = m_groupID;
v61[4] = m_groupID;
v61[5] = m_chance;
v61[6] = 0;
v64 = v60 % v62;
v65 = *(char ***)(*(_QWORD *)&v63 + 8 * v64);
if ( v65 )
{
v66 = *v65;
if ( v60 != *((_DWORD *)*v65 + 2) )
{
while ( *(_QWORD *)v66 )
{
v67 = *(_DWORD *)(*(_QWORD *)v66 + 8LL);
v65 = (char **)v66;
if ( v64 != v67 % v62 )
break;
v66 = *(char **)v66;
if ( v60 == v67 )
goto LABEL_72;
}
goto LABEL_78;
}
LABEL_72:
inserted = *v65;
if ( !*v65 )
goto LABEL_78;
operator delete(v61);
}
else
{
LABEL_78:
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(
(char **)&v84,
v64,
v60,
(char *)v61);
}
*((_DWORD *)inserted + 6) = 0;
++v47;
if ( *((_DWORD *)inserted + 5) != v50->m_chance )
{
*((_DWORD *)inserted + 5) = -1;
v12 = 0;
}
++v50;
*((_DWORD *)inserted + 6) = 1;
if ( v51 == v50 )
{
LABEL_77:
++v74;
goto LABEL_55;
}
}
}
for ( j = v86; j; j = (__int64 *)*j )
{
while ( 1 )
{
v71 = *((_DWORD *)j + 6);
v5 = v71 >= (unsigned int)cocos2d::CCArray::count(a1->m_gameObjects);
v70 = v82;
if ( !v5 )
v12 = 0;
v80 = (__int64 *)((char *)j + 12);
if ( v82 != v83 )
break;
std::vector::_M_emplace_back_aux((__int64)&p, &v80);
j = (__int64 *)*j;
if ( !j )
goto LABEL_88;
}
if ( v82 )
{
*(_QWORD *)v82 = (char *)j + 12;
v70 = v82;
}
v82 = v70 + 8;
}
LABEL_88:
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>::~_Hashtable((__int64)&v84);
if ( v47 <= 10 )
goto LABEL_14;
v73 = 10;
v13 = 35.0;
v15 = 4.5;
v14 = 15.0;
LABEL_15:
v16 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v16);
m_buttonMenu = a1->m_buttonMenu;
cocos2d::CCPoint::CCPoint(
(cocos2d::CCPoint *)&v84,
-(float)((float)(v15 * v13) - (float)(v76 * 0.5)),
(float)(v77 * 0.5) + 10.0);
cocos2d::CCNode::convertToNodeSpace(m_buttonMenu, (const cocos2d::CCPoint *)&v84);
v19 = (char *)p;
v20 = v82;
if ( p == v82 )
{
v22 = (char *)p;
}
else
{
v21 = v82 - (_BYTE *)p;
std::__introsort_loop<__gnu_cxx::__normal_iterator>,long,__gnu_cxx::__ops::_Iter_comp_iter>(
(char *)p,
v82,
2 * (63 - __clz((v82 - (_BYTE *)p) >> 3)),
(unsigned __int8 (__fastcall *)(_QWORD, __int64))chanceObjCompare);
if ( v21 > 135 )
{
v39 = v19 + 128;
std::__insertion_sort<__gnu_cxx::__normal_iterator>,__gnu_cxx::__ops::_Iter_comp_iter>(
(__int64)v19,
v19 + 128,
(unsigned __int8 (__fastcall *)(__int64, __int64))chanceObjCompare);
while ( v20 != v39 )
{
std::__unguarded_linear_insert<__gnu_cxx::__normal_iterator>,__gnu_cxx::__ops::_Val_comp_iter>(
v39,
(unsigned __int8 (__fastcall *)(__int64, __int64))chanceObjCompare);
v39 += 8;
}
}
else
{
std::__insertion_sort<__gnu_cxx::__normal_iterator>,__gnu_cxx::__ops::_Iter_comp_iter>(
(__int64)v19,
v20,
(unsigned __int8 (__fastcall *)(__int64, __int64))chanceObjCompare);
}
v22 = (char *)p;
v19 = v82;
}
if ( (v19 - v22) >> 3 )
{
v23 = 0;
do
{
v24 = *(int **)&v22[8 * v23];
if ( a1->m_gameObject || (v38 = v24[3], v38 >= (unsigned int)cocos2d::CCArray::count(a1->m_gameObjects)) )
v25 = "GJ_button_04.png";
else
v25 = "GJ_button_05.png";
v26 = v24[2];
v27 = v26 <= 0;
v79 = (ButtonSprite *)&byte_124B6C8;
*(float *)&v18 = roundf((float)((float)v26 / (float)TotalChance) * 100.0);
if ( v12 )
{
if ( v26 <= 0 )
v28 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i - ?\n?%%",
(const char *)(unsigned int)*v24,
v18);
else
v28 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i - %i\n%i%%",
(const char *)(unsigned int)*v24);
}
else
{
v40 = (const char *)(unsigned int)*v24;
if ( v26 <= 0 )
v28 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i - ?", v40, v18);
else
v28 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i - %i", v40, v18);
}
CString = cocos2d::CCString::getCString(v28);
v29 = strlen(CString);
sub_D1798C(&v79, CString, v29);
v31 = ButtonSprite::create(v79, (const char *)(unsigned int)(int)v14, 0, 1, 0.35, "bigFont.fnt", v25, v30, 30.0);
v32 = (cocos2d::CCNode *)v31;
if ( v27 )
{
v33 = *(_QWORD *)(v31 + 624);
v34 = *(void (__fastcall **)(__int64, __int64 **))(*(_QWORD *)v33 + 1056LL);
LOBYTE(v84) = -1;
*(_WORD *)((char *)&v84 + 1) = 150;
v34(v33, &v84);
}
v91.ptr = (void (__cdecl *)(cocos2d::CCObject *))a1;
v91.adj = (size_t)SetupRandAdvTriggerPopup::onRemoveFromGroup;
v35 = CCMenuItemSpriteExtra::create(v32, nullptr, v91);
v35->setTag(v35, *v24);
a1->m_buttonMenu->addChild(a1->m_buttonMenu, v35);
setPosition = v35->setPosition;
cocos2d::CCPoint::CCPoint(
(cocos2d::CCPoint *)&v80,
v13 * (float)((int)v23 % v73),
(float)(int)(-38 * vcvtms_s32_f32((float)((int)v23 / v73))));
cocos2d::CCPoint::operator+(&v84, v78, &v80);
setPosition(v35, (const cocos2d::CCPoint *)&v84);
cocos2d::CCArray::addObject(a1->m_groupButtons, v35);
p_m_textOffset = &v79[-1].m_textOffset;
if ( &v79[-1].m_textOffset != (cocos2d::CCPoint *)&qword_124B6B0 )
{
if ( &pthread_create )
{
p_m_caption = (unsigned int *)&v79[-1].m_caption;
do
m_data = __ldaxr(p_m_caption);
while ( __stlxr(m_data - 1, p_m_caption) );
}
else
{
m_data = (int)v79[-1].m_caption.m_data.m_data;
LODWORD(v79[-1].m_caption.m_data.m_data) = m_data - 1;
}
if ( m_data <= 0 )
operator delete(p_m_textOffset);
}
++v23;
v22 = (char *)p;
}
while ( (int)v23 <= 19 && v23 < (v82 - (_BYTE *)p) >> 3 );
}
if ( v22 )
operator delete(v22);
}