//
// cocos2d::CCMenu::alignItemsInRowsWithArray from 0x180058830 to 0x180058d3b (1291 bytes)
//
// 3 xrefs:
// > cocos2d::CCMenu::alignItemsInRows @ 0x1800587f4
// > ??> @ 0x1801438a8
// > ??> @ 0x1801b2a6c
//
// 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
//
// Hidden C++ exception states: #wind=3
void __fastcall cocos2d::CCMenu::alignItemsInRowsWithArray(cocos2d::CCMenu *this, struct cocos2d::CCArray *a2)
{
cocos2d::CCMenu *v2; // rdi
int v3; // ebx
int v4; // r15d
int v5; // esi
unsigned int v6; // r13d
cocos2d::CCArray *m_pChildren; // rcx
cocos2d::CCArray *v8; // rax
cocos2d::ccArray *data; // r12
__int64 num; // rax
cocos2d::CCObject **arr; // r12
_BYTE *v12; // rdi
_BYTE *v13; // rbx
__int64 v14; // r14
float v15; // xmm6_4
cocos2d::CCDirector *v16; // rax
__int64 v17; // r12
int v18; // r15d
unsigned int v19; // r14d
float v20; // xmm8_4
float v21; // xmm9_4
cocos2d::CCArray *v22; // rcx
char *v23; // rdi
int *v24; // rbx
cocos2d::CCArray *v25; // rax
cocos2d::ccArray *v26; // rcx
__int64 v27; // rax
cocos2d::CCObject **v28; // rdi
__int64 v29; // rax
__int64 v30; // rsi
float v31; // xmm6_4
__int64 v32; // rbx
float *v33; // rax
int *v34; // rax
char *v35; // rax
void *v36; // rcx
int v37; // [rsp+38h] [rbp-A9h] BYREF
unsigned int v38; // [rsp+3Ch] [rbp-A5h]
_BYTE *v39; // [rsp+40h] [rbp-A1h]
_BYTE *v40; // [rsp+48h] [rbp-99h]
void *v41[2]; // [rsp+50h] [rbp-91h] BYREF
_BYTE *v42; // [rsp+60h] [rbp-81h]
void *Block[2]; // [rsp+68h] [rbp-79h] BYREF
_BYTE *v44; // [rsp+78h] [rbp-69h]
cocos2d::CCObject **v45; // [rsp+80h] [rbp-61h]
float v46; // [rsp+8Ch] [rbp-55h]
void *v47[15]; // [rsp+90h] [rbp-51h] BYREF
cocos2d::CCObject **i; // [rsp+148h] [rbp+67h]
unsigned int v50; // [rsp+158h] [rbp+77h] BYREF
int v51; // [rsp+160h] [rbp+7Fh]
v2 = this;
sub_180059140(v47, a2);
*(_OWORD *)v41 = 0;
v40 = nullptr;
v42 = nullptr;
*(_OWORD *)Block = 0;
v39 = nullptr;
v44 = nullptr;
v3 = -10;
v51 = -10;
v4 = -5;
v50 = 0;
v5 = 0;
v6 = 0;
m_pChildren = v2->m_pChildren;
if ( m_pChildren )
{
if ( (unsigned int)cocos2d::CCArray::count(m_pChildren) )
{
v8 = v2->m_pChildren;
if ( v8 )
{
data = v8->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
v45 = &arr[num - 1];
if ( arr <= v45 )
{
v12 = v41[1];
v13 = Block[1];
do
{
if ( !*arr )
break;
v14 = _RTDynamicCast(
*arr,
0,
&cocos2d::CCObject `RTTI Type Descriptor',
&cocos2d::CCNode `RTTI Type Descriptor',
0);
if ( v14 )
{
v38 = *((_DWORD *)v47[0] + v50);
v15 = *(float *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v14 + 304LL))(v14);
if ( (float)v5 >= v15 || isnan(v15) )
v15 = (float)v5;
v5 = (int)v15;
v37 = (int)v15;
v4 += (int)(float)(*(float *)((*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v14 + 304LL))(v14) + 4)
+ 5.0);
if ( ++v6 >= v38 )
{
if ( v12 == v40 )
{
sub_180030780((const void **)v41, v12, &v37);
v40 = v42;
v12 = v41[1];
}
else
{
*(_DWORD *)v12 = v5;
v12 += 4;
v41[1] = v12;
}
v37 = v4;
if ( v13 == v39 )
{
sub_180030780((const void **)Block, v13, &v37);
v39 = v44;
v13 = Block[1];
}
else
{
*(_DWORD *)v13 = v4;
v13 += 4;
Block[1] = v13;
}
v51 += v5 + 10;
v6 = 0;
v5 = 0;
v4 = -5;
++v50;
}
}
++arr;
}
while ( arr <= v45 );
v3 = v51;
v2 = this;
}
}
}
}
}
v16 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v16);
v17 = 0;
v18 = 0;
v19 = 0;
v20 = (float)(v3 / -2);
v21 = 0.0;
v22 = v2->m_pChildren;
v23 = (char *)v41[0];
v24 = (int *)Block[0];
if ( v22 )
{
if ( (unsigned int)cocos2d::CCArray::count(v22) )
{
v25 = this->m_pChildren;
if ( v25 )
{
v26 = v25->data;
v27 = v26->num;
if ( (_DWORD)v27 )
{
v28 = v26->arr;
for ( i = &v28[v27 - 1]; v28 <= i; ++v28 )
{
if ( !*v28 )
break;
v29 = _RTDynamicCast(
*v28,
0,
&cocos2d::CCObject `RTTI Type Descriptor',
&cocos2d::CCNode `RTTI Type Descriptor',
0);
v30 = v29;
if ( v29 )
{
if ( !v19 )
{
v19 = *((_DWORD *)v47[0] + v17);
v21 = (float)v24[v17];
}
v31 = *(float *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v29 + 304LL))(v29);
if ( (float)v18 >= v31 || isnan(v31) )
v31 = (float)v18;
v18 = (int)v31;
v32 = *(_QWORD *)v30;
v33 = kmVec2Fill((float *)&v50, (float)(*((_DWORD *)v41[0] + v17) >> 1) + v20, v21 - (float)(v46 * 0.5));
(*(void (__fastcall **)(__int64, float *))(v32 + 184))(v30, v33);
v21 = v21
- (float)(*(float *)((*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v30 + 304LL))(v30) + 4) + 10.0);
++v6;
v24 = (int *)Block[0];
if ( v6 >= v19 )
{
v20 = v20 + (float)(v18 + 5);
v6 = 0;
v19 = 0;
v18 = 0;
v17 = (unsigned int)(v17 + 1);
}
}
}
v23 = (char *)v41[0];
}
}
}
}
if ( v24 )
{
v34 = v24;
if ( (unsigned __int64)(4 * ((v39 - (_BYTE *)v24) >> 2)) >= 0x1000 )
{
v24 = *((int **)v24 - 1);
if ( (unsigned __int64)((char *)v34 - (char *)v24 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v24);
}
if ( v23 )
{
v35 = v23;
if ( (unsigned __int64)(4 * ((v40 - v23) >> 2)) >= 0x1000 )
{
v23 = *((char **)v23 - 1);
if ( (unsigned __int64)(v35 - v23 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v23);
}
v36 = v47[0];
if ( v47[0] )
{
if ( (((char *)v47[2] - (char *)v47[0]) & 0xFFFFFFFFFFFFFFFCuLL) >= 0x1000 )
{
v36 = *((void **)v47[0] - 1);
if ( (unsigned __int64)((char *)v47[0] - (char *)v36 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v36);
}
}