//
// SetupRandAdvTriggerPopup::updateGroupIDButtons from 0x528028 to 0x5285d4 (1452 bytes)
//
// 4 xrefs:
// > SetupRandAdvTriggerPopup::init @ 0x528bd4
// > SetupRandAdvTriggerPopup::addChance @ 0x528e50
// > SetupRandAdvTriggerPopup::removeGroupID @ 0x528e9a
// > SetupRandAdvTriggerPopup::onAddChance @ 0x528f2a
//
// 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; // r7
bool v3; // cf
cocos2d::CCArray *m_groupButtons; // r0
unsigned int v5; // r1
int v6; // r0
RandTriggerGameObject *m_gameObject; // r5
ChanceObject *m_finish; // r7
float j; // r6
float v10; // s16
float v11; // s17
int v12; // r8
float v13; // s18
float v14; // r0
int *v15; // r6
size_t v16; // r5
unsigned int v17; // r7
int v18; // r9
RandTriggerGameObject *v19; // r5
ChanceObject *v20; // r3
int v21; // r5
unsigned int v22; // r8
_DWORD *v23; // r3
_DWORD *v24; // r11
int v25; // r3
int v26; // r11
_DWORD *v27; // r0
unsigned int v28; // r2
float y; // r8
int v30; // r3
_DWORD **v31; // r11
_DWORD *k; // r1
_DWORD *inserted; // r8
int v34; // r3
_DWORD *m; // r5
unsigned int v36; // r10
unsigned int v37; // r0
int v38; // r3
cocos2d::CCDirector *v39; // r0
cocos2d::CCMenu *m_buttonMenu; // r6
char *v41; // r7
char *v42; // r9
signed int n; // r6
int v44; // r5
char *v45; // r5
int *v46; // r5
unsigned int v47; // r7
char *v48; // r10
_BOOL4 v49; // r9
int v50; // r0
cocos2d::CCString *v51; // r0
char *CString; // r0
ButtonSprite *v53; // r0
cocos2d::CCNode *v54; // r7
CCMenuItemSpriteExtra *v55; // r7
float v56; // r0
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // r10
char *v58; // r0
cocos2d::CCLabelBMFont *m_label; // r0
void (__fastcall *setColor)(cocos2d::CCLabelBMFont *__hidden, const cocos2d::ccColor3B *); // r3
float v61; // [sp+10h] [bp-7Ch]
int v62; // [sp+14h] [bp-78h]
ChanceObject *v63; // [sp+1Ch] [bp-70h]
ButtonSprite *v64; // [sp+38h] [bp-54h] BYREF
cocos2d::CCSize v65; // [sp+3Ch] [bp-50h] BYREF
cocos2d::CCPoint v66; // [sp+44h] [bp-48h] BYREF
cocos2d::CCPoint v67; // [sp+4Ch] [bp-40h] BYREF
cocos2d::CCPoint v68; // [sp+54h] [bp-38h] BYREF
void *p; // [sp+5Ch] [bp-30h] BYREF
char *v70; // [sp+60h] [bp-2Ch]
int v71; // [sp+64h] [bp-28h]
cocos2d::CCPoint v72; // [sp+68h] [bp-24h] BYREF
_DWORD *v73; // [sp+70h] [bp-1Ch]
int v74; // [sp+74h] [bp-18h]
_DWORD v75[2]; // [sp+78h] [bp-14h] BYREF
int v76; // [sp+80h] [bp-Ch] BYREF
for ( i = 0; ; ++i )
{
v3 = i >= cocos2d::CCArray::count(a1->m_groupButtons);
m_groupButtons = a1->m_groupButtons;
if ( v3 )
break;
v5 = i;
v6 = cocos2d::CCArray::objectAtIndex(m_groupButtons, v5);
(*(void (__fastcall **)(int))(*(_DWORD *)v6 + 252))(v6);
}
cocos2d::CCArray::removeAllObjects(m_groupButtons);
m_gameObject = (RandTriggerGameObject *)a1->m_gameObject;
p = nullptr;
v70 = nullptr;
v71 = 0;
if ( m_gameObject )
{
m_finish = m_gameObject->m_chanceObjects.m_finish;
for ( j = *(float *)&m_gameObject->m_chanceObjects.m_start; (ChanceObject *)LODWORD(j) != m_finish; LODWORD(j) += 16 )
{
v72.x = j;
std::vector::emplace_back((int)&p, &v72);
}
RandTriggerGameObject::getTotalChance(m_gameObject);
v62 = 1;
v10 = 2.0;
v11 = 66.0;
v12 = 5;
v13 = 40.0;
}
else
{
v73 = nullptr;
v74 = 0;
v75[0] = 1065353216;
v75[1] = 0;
v14 = COERCE_FLOAT(sub_773A14(v75, 10));
v72.y = v14;
if ( LODWORD(v14) == 1 )
{
v76 = 0;
v15 = &v76;
}
else
{
if ( LODWORD(v14) >= 0x40000000 )
sub_772FB4(LODWORD(v14));
v16 = 4 * LODWORD(v14);
v15 = (int *)operator new(4 * LODWORD(v14));
memset(v15, 0, v16);
}
v17 = 0;
v18 = 0;
LODWORD(v72.x) = v15;
v62 = 1;
while ( v17 < cocos2d::CCArray::count(a1->m_gameObjects) )
{
v19 = (RandTriggerGameObject *)cocos2d::CCArray::objectAtIndex(a1->m_gameObjects, v17);
RandTriggerGameObject::getTotalChance(v19);
v20 = v19->m_chanceObjects.m_finish;
v21 = (int)&v19->m_chanceObjects.m_start[1];
v63 = v20;
while ( v63 != (ChanceObject *)(v21 - 16) )
{
v22 = *(_DWORD *)(v21 - 16);
v23 = *(_DWORD **)(LODWORD(v72.x) + 4 * (v22 % LODWORD(v72.y)));
if ( v23 )
{
v24 = (_DWORD *)*v23;
if ( *v23 )
{
v25 = 0;
do
{
if ( v22 == v24[1] )
{
++v25;
}
else if ( v25 )
{
goto LABEL_82;
}
v24 = (_DWORD *)*v24;
}
while ( v24 && v24[1] % LODWORD(v72.y) == *(_DWORD *)(v21 - 16) % LODWORD(v72.y) );
if ( v25 )
LABEL_82:
__und(0xFFu);
}
}
v26 = *(_DWORD *)(v21 - 8);
v27 = (_DWORD *)operator new(0x18u);
v28 = *(_DWORD *)(v21 - 16);
v27[4] = v26;
v27[2] = v22;
v27[1] = v28;
v27[3] = v22;
v27[5] = 0;
y = v72.y;
*v27 = 0;
v30 = v28 % LODWORD(y);
v31 = *(_DWORD ***)(LODWORD(v72.x) + 4 * (v28 % LODWORD(y)));
if ( !v31 )
goto LABEL_37;
for ( k = *v31; v28 != k[1]; k = (_DWORD *)*k )
{
if ( !*k )
goto LABEL_37;
v31 = (_DWORD **)k;
if ( *(_DWORD *)(*k + 4) % LODWORD(y) != v30 )
goto LABEL_37;
}
inserted = *v31;
if ( *v31 )
operator delete(v27);
else
LABEL_37:
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)&v72,
v30,
v28,
v27);
inserted[5] = 0;
++v18;
v34 = *(_DWORD *)(v21 - 8);
v21 += 16;
if ( inserted[4] != v34 )
{
inserted[4] = -1;
v62 = 0;
}
inserted[5] = 1;
}
++v17;
}
for ( m = v73; m; m = (_DWORD *)*m )
{
v36 = m[5];
v37 = cocos2d::CCArray::count(a1->m_gameObjects);
v38 = v62;
LODWORD(v68.x) = m + 2;
if ( v36 < v37 )
v38 = 0;
v62 = v38;
std::vector::emplace_back((int)&p, &v68);
}
v11 = 35.0;
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((int)&v72);
if ( v18 <= 10 )
v12 = 5;
else
v12 = 10;
v10 = 2.0;
v13 = 40.0;
if ( v18 > 10 )
v10 = 4.5;
else
v11 = 66.0;
if ( v18 > 10 )
v13 = 15.0;
}
v39 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(&v65, v39);
m_buttonMenu = a1->m_buttonMenu;
cocos2d::CCPoint::CCPoint(&v72, (float)(v65.width * 0.5) - (float)(v10 * v11), (float)(v65.height * 0.5) + 10.0);
cocos2d::CCNode::convertToNodeSpace(&v66, m_buttonMenu, &v72);
v41 = (char *)p;
v42 = v70;
if ( p != v70 )
{
v44 = v70 - (_BYTE *)p;
std::__introsort_loop<__gnu_cxx::__normal_iterator>,int,__gnu_cxx::__ops::_Iter_comp_iter>(
(int)p,
v70,
2 * (31 - __clz((v70 - (_BYTE *)p) >> 2)),
(int (__fastcall *)(_DWORD, int, int, unsigned int))chanceObjCompare);
if ( v44 <= 67 )
{
std::__insertion_sort<__gnu_cxx::__normal_iterator>,__gnu_cxx::__ops::_Iter_comp_iter>(
v41,
v42,
(int (__fastcall *)(int, _DWORD))chanceObjCompare);
}
else
{
v45 = v41 + 64;
std::__insertion_sort<__gnu_cxx::__normal_iterator>,__gnu_cxx::__ops::_Iter_comp_iter>(
v41,
v41 + 64,
(int (__fastcall *)(int, _DWORD))chanceObjCompare);
while ( v45 != v42 )
{
std::__unguarded_linear_insert<__gnu_cxx::__normal_iterator>,__gnu_cxx::__ops::_Val_comp_iter>(
v45,
(int (__fastcall *)(int, _DWORD))chanceObjCompare);
v45 += 4;
}
}
}
for ( n = 0; n < (unsigned int)((v70 - (_BYTE *)p) >> 2) && n != 20; ++n )
{
v46 = *((int **)p + n);
if ( a1->m_gameObject || (v47 = v46[3], v47 >= cocos2d::CCArray::count(a1->m_gameObjects)) )
v48 = "GJ_button_04.png";
else
v48 = "GJ_button_05.png";
v49 = v46[2] <= 0;
v64 = (ButtonSprite *)&unk_ACDDA8;
v50 = lroundf();
if ( v62 )
{
if ( !v49 )
{
v51 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i - %i\n%i%%",
(const char *)*v46,
v46[2],
v50);
goto LABEL_69;
}
v58 = "%i - ?\n?%%";
}
else
{
if ( !v49 )
{
v51 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i - %i",
(const char *)*v46,
v46[2],
v50);
goto LABEL_69;
}
v58 = "%i - ?";
}
v51 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)v58, (const char *)*v46);
LABEL_69:
CString = (char *)cocos2d::CCString::getCString(v51);
sub_7753D4((int)&v64, CString);
v53 = ButtonSprite::create(
v64,
(const char *)(int)v13,
0,
0.35,
1,
"bigFont.fnt",
v48,
(const char *)0x41F00000,
v61);
v54 = v53;
if ( v49 )
{
m_label = v53->m_label;
setColor = m_label->setColor;
LOWORD(v68.x) = -26881;
BYTE2(v68.x) = 0;
setColor(m_label, (const cocos2d::ccColor3B *)&v68);
}
LODWORD(v72.x) = SetupRandAdvTriggerPopup::onRemoveFromGroup;
v72.y = 0.0;
v55 = CCMenuItemSpriteExtra::create(
v54,
nullptr,
(cocos2d::SEL_MenuHandler)__PAIR64__(SetupRandAdvTriggerPopup::onRemoveFromGroup, (unsigned int)a1));
v55->setTag(v55, *v46);
a1->m_buttonMenu->addChild(a1->m_buttonMenu, v55);
v56 = floorf((float)(n / v12));
setPosition = v55->setPosition;
cocos2d::CCPoint::CCPoint(&v67, v11 * (float)(n % v12), (float)(-38 * (int)v56));
cocos2d::CCPoint::operator+(&v68, &v66, &v67);
setPosition(v55, &v68);
cocos2d::CCArray::addObject(a1->m_groupButtons, v55);
sub_774008(&v64);
}
if ( p )
operator delete(p);
}